Exemple #1
0
 /**
  * Set the (new) value of the {@code Content-Disposition} header for {@code form-data}.
  *
  * @param name the control name
  * @param filename the filename (may be {@code null})
  */
 public void setContentDispositionFormData(String name, String filename) {
   StringBuilder builder = new StringBuilder("form-data; name=\"");
   builder.append(name).append('\"');
   if (filename != null) {
     builder.append("; filename=\"");
     builder.append(filename).append('\"');
   }
   set(CONTENT_DISPOSITION, builder.toString());
 }
Exemple #2
0
 /**
  * Set the list of acceptable {@linkplain Charset charsets}, as specified by the {@code
  * Accept-Charset} header.
  */
 public void setAcceptCharset(List<Charset> acceptableCharsets) {
   StringBuilder builder = new StringBuilder();
   for (Iterator<Charset> iterator = acceptableCharsets.iterator(); iterator.hasNext(); ) {
     Charset charset = iterator.next();
     builder.append(charset.name().toLowerCase(Locale.ENGLISH));
     if (iterator.hasNext()) {
       builder.append(", ");
     }
   }
   set(ACCEPT_CHARSET, builder.toString());
 }
 protected void addHeaders(HttpHeaders headers, HttpRequestBase uriRequest) {
   if (headers == null) {
     headers = new HttpHeaders();
   }
   // Add default accept headers
   if (!headers.containsKey(HttpHeaders.ACCEPT)) {
     headers.set(HttpHeaders.ACCEPT, "*/*");
   }
   // Add default user agent
   if (!headers.containsKey(HttpHeaders.USER_AGENT)) {
     headers.set(HttpHeaders.USER_AGENT, "apache/httpclient4");
   }
   for (Iterator<Entry<String, List<String>>> headerIterator = headers.entrySet().iterator();
       headerIterator.hasNext(); ) {
     Entry<String, List<String>> header = headerIterator.next();
     if (HttpHeaders.COOKIE.equalsIgnoreCase(header.getKey())) {
       uriRequest.addHeader(header.getKey(), StringUtil.join(header.getValue(), ';'));
     } else {
       for (String headerValue : header.getValue()) {
         uriRequest.addHeader(header.getKey(), headerValue != null ? headerValue : "");
       }
     }
   }
 }
Exemple #4
0
 /** Set the length of the body in bytes, as specified by the {@code Content-Length} header. */
 public void setContentLength(long contentLength) {
   set(CONTENT_LENGTH, Long.toString(contentLength));
 }
Exemple #5
0
 /**
  * Set the {@linkplain ContentType media type} of the body, as specified by the {@code
  * Content-Type} header.
  */
 public void setContentType(ContentType contentType) {
   set(CONTENT_TYPE, contentType.toString());
 }
Exemple #6
0
 /**
  * Set the list of acceptable {@linkplain MediaType media types}, as specified by the {@code
  * Accept} header.
  */
 public void setAccept(List<ContentType> acceptableMediaTypes) {
   set(ACCEPT, ContentType.toString(acceptableMediaTypes));
 }
Exemple #7
0
 /** Set the (new) value of the {@code Access-Control-Allow-Credentials} response header. */
 public void setAccessControlAllowCredentials(boolean allowCredentials) {
   set(ACCESS_CONTROL_ALLOW_CREDENTIALS, Boolean.toString(allowCredentials));
 }
Exemple #8
0
 /** Sets the (new) value of the {@code Range} header. */
 public void setRange(String range) {
   set(RANGE, range);
 }
Exemple #9
0
 /**
  * Set the given date under the given header name after formatting it as a string using the
  * pattern {@code "EEE, dd MMM yyyy HH:mm:ss zzz"}. The equivalent of {@link #set(String, String)}
  * but for date headers.
  */
 public void setDate(String headerName, long date) {
   SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMATS[0], Locale.US);
   dateFormat.setTimeZone(GMT);
   set(headerName, dateFormat.format(new Date(date)));
 }
Exemple #10
0
 /** Set the (new) values of the {@code If-None-Match} header. */
 public void setIfNoneMatch(List<String> ifNoneMatchList) {
   set(IF_NONE_MATCH, toCommaDelimitedString(ifNoneMatchList));
 }
Exemple #11
0
 /** Set the (new) value of the {@code Access-Control-Allow-Methods} response header. */
 public void setAccessControlAllowMethods(List<HttpMethod> allowedMethods) {
   set(ACCESS_CONTROL_ALLOW_METHODS, StringUtil.join(allowedMethods, ','));
 }
Exemple #12
0
 /** Set the (new) value of the {@code Access-Control-Request-Headers} request header. */
 public void setAccessControlRequestHeaders(List<String> requestHeaders) {
   set(ACCESS_CONTROL_REQUEST_HEADERS, toCommaDelimitedString(requestHeaders));
 }
Exemple #13
0
 /** Set the (new) value of the {@code Access-Control-Request-Method} request header. */
 public void setAccessControlRequestMethod(HttpMethod requestedMethod) {
   set(ACCESS_CONTROL_REQUEST_METHOD, requestedMethod.name());
 }
Exemple #14
0
 /** Set the (new) value of the {@code Access-Control-Max-Age} response header. */
 public void setAccessControlMaxAge(long maxAge) {
   set(ACCESS_CONTROL_MAX_AGE, Long.toString(maxAge));
 }
Exemple #15
0
 /** Set the (new) value of the {@code Access-Control-Expose-Headers} response header. */
 public void setAccessControlExposeHeaders(List<String> exposedHeaders) {
   set(ACCESS_CONTROL_EXPOSE_HEADERS, toCommaDelimitedString(exposedHeaders));
 }
Exemple #16
0
 /** Set the (new) value of the {@code Access-Control-Allow-Origin} response header. */
 public void setAccessControlAllowOrigin(String allowedOrigin) {
   set(ACCESS_CONTROL_ALLOW_ORIGIN, allowedOrigin);
 }
Exemple #17
0
 /** Set the (new) entity tag of the body, as specified by the {@code ETag} header. */
 public void setETag(String eTag) {
   set(ETAG, eTag);
 }
Exemple #18
0
 /** Set the (new) value of the {@code Origin} header. */
 public void setOrigin(String origin) {
   set(ORIGIN, origin);
 }
Exemple #19
0
 /** Set the (new) value of the {@code If-None-Match} header. */
 public void setIfNoneMatch(String ifNoneMatch) {
   set(IF_NONE_MATCH, ifNoneMatch);
 }
Exemple #20
0
 /** Set the (new) value of the {@code Access-Control-Allow-Headers} response header. */
 public void setAccessControlAllowHeaders(List<String> allowedHeaders) {
   set(ACCESS_CONTROL_ALLOW_HEADERS, toCommaDelimitedString(allowedHeaders));
 }
Exemple #21
0
 /** Set the (new) location of a resource, as specified by the {@code Location} header. */
 public void setLocation(URI location) {
   set(LOCATION, location.toASCIIString());
 }
Exemple #22
0
 /**
  * Set the set of allowed {@link HttpMethod HTTP methods}, as specified by the {@code Allow}
  * header.
  */
 public void setAllow(Set<HttpMethod> allowedMethods) {
   set(ALLOW, StringUtil.join(allowedMethods, ','));
 }
Exemple #23
0
 /** Set the (new) value of the {@code Pragma} header. */
 public void setPragma(String pragma) {
   set(PRAGMA, pragma);
 }
Exemple #24
0
 /** Set the (new) value of the {@code Cache-Control} header. */
 public void setCacheControl(String cacheControl) {
   set(CACHE_CONTROL, cacheControl);
 }
Exemple #25
0
 /** Set the (new) value of the {@code Upgrade} header. */
 public void setUpgrade(String upgrade) {
   set(UPGRADE, upgrade);
 }
Exemple #26
0
 /** Set the (new) value of the {@code Connection} header. */
 public void setConnection(String connection) {
   set(CONNECTION, connection);
 }
Exemple #27
0
 @Override
 public void setAll(Map<String, String> values) {
   for (Entry<String, String> entry : values.entrySet()) {
     set(entry.getKey(), entry.getValue());
   }
 }
Exemple #28
0
 /** Set the (new) value of the {@code Connection} header. */
 public void setConnection(List<String> connection) {
   set(CONNECTION, toCommaDelimitedString(connection));
 }