/** * 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()); }
/** * 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 : ""); } } } }
/** 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)); }
/** * 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()); }
/** * 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)); }
/** 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)); }
/** Sets the (new) value of the {@code Range} header. */ public void setRange(String range) { set(RANGE, range); }
/** * 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))); }
/** Set the (new) values of the {@code If-None-Match} header. */ public void setIfNoneMatch(List<String> ifNoneMatchList) { set(IF_NONE_MATCH, toCommaDelimitedString(ifNoneMatchList)); }
/** 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, ',')); }
/** 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)); }
/** 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()); }
/** 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)); }
/** 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)); }
/** Set the (new) value of the {@code Access-Control-Allow-Origin} response header. */ public void setAccessControlAllowOrigin(String allowedOrigin) { set(ACCESS_CONTROL_ALLOW_ORIGIN, allowedOrigin); }
/** Set the (new) entity tag of the body, as specified by the {@code ETag} header. */ public void setETag(String eTag) { set(ETAG, eTag); }
/** Set the (new) value of the {@code Origin} header. */ public void setOrigin(String origin) { set(ORIGIN, origin); }
/** Set the (new) value of the {@code If-None-Match} header. */ public void setIfNoneMatch(String ifNoneMatch) { set(IF_NONE_MATCH, ifNoneMatch); }
/** 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)); }
/** Set the (new) location of a resource, as specified by the {@code Location} header. */ public void setLocation(URI location) { set(LOCATION, location.toASCIIString()); }
/** * 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, ',')); }
/** Set the (new) value of the {@code Pragma} header. */ public void setPragma(String pragma) { set(PRAGMA, pragma); }
/** Set the (new) value of the {@code Cache-Control} header. */ public void setCacheControl(String cacheControl) { set(CACHE_CONTROL, cacheControl); }
/** Set the (new) value of the {@code Upgrade} header. */ public void setUpgrade(String upgrade) { set(UPGRADE, upgrade); }
/** Set the (new) value of the {@code Connection} header. */ public void setConnection(String connection) { set(CONNECTION, connection); }
@Override public void setAll(Map<String, String> values) { for (Entry<String, String> entry : values.entrySet()) { set(entry.getKey(), entry.getValue()); } }
/** Set the (new) value of the {@code Connection} header. */ public void setConnection(List<String> connection) { set(CONNECTION, toCommaDelimitedString(connection)); }