• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.adservices.service.common.httpclient;
18 
19 import android.net.Uri;
20 
21 import com.google.auto.value.AutoValue;
22 import com.google.common.collect.ImmutableMap;
23 import com.google.common.collect.ImmutableSet;
24 
25 /** Input to the {@link AdServicesHttpsClient}, which makes request to download content */
26 @AutoValue
27 public abstract class AdServicesHttpClientRequest {
28 
29     /** @return uri that is used to make the request */
getUri()30     public abstract Uri getUri();
31 
32     /** @return request properties that need to be piggybacked to the url connection */
getRequestProperties()33     public abstract ImmutableMap<String, String> getRequestProperties();
34 
35     /** @return set of keys that we want in the {@link AdServicesHttpClientResponse} */
getResponseHeaderKeys()36     public abstract ImmutableSet<String> getResponseHeaderKeys();
37 
38     /** @return boolean is the results should be cached or not */
getUseCache()39     public abstract boolean getUseCache();
40 
41     /**
42      * @param uri see {@link #getUri()}
43      * @param requestProperties see {@link #getRequestProperties()}
44      * @param responseHeaderKeys see {@link #getResponseHeaderKeys()}
45      * @param useCache see {@link #getUseCache()}
46      * @return an instance of {@link AdServicesHttpClientRequest}
47      */
create( Uri uri, ImmutableMap<String, String> requestProperties, ImmutableSet<String> responseHeaderKeys, boolean useCache)48     public static AdServicesHttpClientRequest create(
49             Uri uri,
50             ImmutableMap<String, String> requestProperties,
51             ImmutableSet<String> responseHeaderKeys,
52             boolean useCache) {
53         return builder()
54                 .setUri(uri)
55                 .setRequestProperties(requestProperties)
56                 .setResponseHeaderKeys(responseHeaderKeys)
57                 .setUseCache(useCache)
58                 .build();
59     }
60 
61     /** @return a builder that cane be used to build an {@link AdServicesHttpClientRequest} */
builder()62     public static AdServicesHttpClientRequest.Builder builder() {
63         return new AutoValue_AdServicesHttpClientRequest.Builder()
64                 .setRequestProperties(ImmutableMap.of())
65                 .setResponseHeaderKeys(ImmutableSet.of())
66                 .setUseCache(false);
67     }
68 
69     /** Builder that cane be used to build an {@link AdServicesHttpClientRequest} */
70     @AutoValue.Builder
71     public abstract static class Builder {
72 
73         /** @param uri that is used to make the request */
setUri(Uri uri)74         public abstract AdServicesHttpClientRequest.Builder setUri(Uri uri);
75 
76         /** @param queryParams that need to be piggybacked to the url connection */
setRequestProperties( ImmutableMap<String, String> queryParams)77         public abstract AdServicesHttpClientRequest.Builder setRequestProperties(
78                 ImmutableMap<String, String> queryParams);
79 
80         /**
81          * @param responseHeaderKeys set of keys that we want in the {@link
82          *     AdServicesHttpClientResponse}
83          */
setResponseHeaderKeys( ImmutableSet<String> responseHeaderKeys)84         public abstract AdServicesHttpClientRequest.Builder setResponseHeaderKeys(
85                 ImmutableSet<String> responseHeaderKeys);
86 
87         /** @param useCache flag to cache the response of this request */
setUseCache(boolean useCache)88         public abstract AdServicesHttpClientRequest.Builder setUseCache(boolean useCache);
89 
90         /** @return an {@link AdServicesHttpClientRequest} */
build()91         public abstract AdServicesHttpClientRequest build();
92     }
93 }
94