Esempio n. 1
0
 /**
  * Sets the etag.
  *
  * @param etag the etag.
  * @return this
  */
 public Builder etag(final String etag) {
   if (etag == null) {
     mHeaders.removeAll(ETAG);
   } else {
     mHeaders.set(ETAG, etag);
   }
   return this;
 }
Esempio n. 2
0
  private static void appendHeaders(Request.Builder builder, Map<String, String> headers) {
    Headers.Builder headerBuilder = new Headers.Builder();
    if (headers == null || headers.isEmpty()) return;

    for (String key : headers.keySet()) {
      headerBuilder.add(key, headers.get(key));
    }
    builder.headers(headerBuilder.build());
  }
Esempio n. 3
0
  protected void appendHeaders() {
    Headers.Builder headerBuilder = new Headers.Builder();
    if (headers == null || headers.isEmpty()) return;

    for (String key : headers.keySet()) {
      headerBuilder.add(key, headers.get(key));
    }
    builder.headers(headerBuilder.build());
  }
Esempio n. 4
0
 public PostRequest addHeader(String key, String value) {
   if (headers == null) {
     headers = new Headers.Builder();
   }
   headers.add(key, value);
   return this;
 }
Esempio n. 5
0
 public Request create() {
   builder.url(url);
   builder.tag(tag);
   if (headers != null) {
     builder.headers(headers.build());
   }
   builder.post(requestBody);
   return builder.build();
 }
Esempio n. 6
0
 /**
  * Removes all values for the specified header name.
  *
  * @param name the header name.
  * @return this
  */
 public Builder removeHeader(final String name) {
   mHeaders.removeAll(name);
   return this;
 }
Esempio n. 7
0
 /**
  * Adds the value for the header with the specified name. It doesn't replaces any previous value
  * set for the same header name.
  *
  * @param name the header name.
  * @param value the header value.
  * @return this
  */
 public Builder addHeader(final String name, final String value) {
   mHeaders.add(name, value);
   return this;
 }
Esempio n. 8
0
 /**
  * Sets the value for the header with the specified name. It replaces any previous value set for
  * the same header name.
  *
  * @param name the header name.
  * @param value the header value.
  * @return this
  */
 public Builder header(final String name, final String value) {
   mHeaders.set(name, value);
   return this;
 }
Esempio n. 9
0
 /**
  * Sets the location header.
  *
  * @param path the location path.
  * @return this
  */
 public Builder location(final String path) {
   mHeaders.set(LOCATION, path);
   return this;
 }
Esempio n. 10
0
 /**
  * Sets the location header.
  *
  * @param url the location.
  * @return this
  */
 public Builder location(final HttpUrl url) {
   mHeaders.set(LOCATION, url.toString());
   return this;
 }
Esempio n. 11
0
 /**
  * Sets the strict transport security header, with the specified max-age.
  *
  * @param secs the max-age in seconds.
  * @return this
  */
 public Builder hsts(final long secs) {
   mHeaders.set(STRICT_TRANSPORT_SECURITY, "max-age=" + secs);
   return this;
 }
Esempio n. 12
0
 @Override
 protected Headers.Builder headersBuilder() {
   Headers.Builder builder = super.headersBuilder();
   builder.add("Host", HOST);
   return builder;
 }
Esempio n. 13
0
 /**
  * Sets the cache control header to private.
  *
  * @return this
  */
 public Builder priv() {
   mHeaders.add(CACHE_CONTROL, "private");
   return this;
 }
Esempio n. 14
0
 /**
  * Sets the cache control header to no-store and removes the etag.
  *
  * @return this
  */
 public Builder noStore() {
   mHeaders.removeAll(ETAG).set(CACHE_CONTROL, "no-store");
   return this;
 }
Esempio n. 15
0
 /**
  * Sets the etag (optional) and the cache control header to no-cache.
  *
  * @param etag the etag (optional).
  * @return this
  */
 public Builder noCache(final String etag) {
   if (etag != null) mHeaders.set(ETAG, etag);
   mHeaders.set(CACHE_CONTROL, "no-cache");
   return this;
 }
Esempio n. 16
0
 /**
  * Sets the content length header to the specified length.
  *
  * @param length the content length.
  * @return this
  */
 public Builder contentLength(final long length) {
   mHeaders.set(CONTENT_LENGTH, String.valueOf(length));
   return this;
 }
Esempio n. 17
0
 /**
  * Sets the content type header to the specified media type.
  *
  * @param contentType the media type.
  * @return this
  */
 public Builder contentType(final MediaType contentType) {
   mHeaders.set(CONTENT_TYPE, contentType.toString());
   return this;
 }
Esempio n. 18
0
 /**
  * Sets the cache control max-age value.
  *
  * @param secs the max-age value in seconds.
  * @return this
  */
 public Builder maxAge(final long secs) {
   mHeaders.add(CACHE_CONTROL, "max-age=" + secs);
   return this;
 }