protected Headers buildHeaders() { List<Tuple2<String, String>> list = new ArrayList<>(); for (Map.Entry<String,String[]> entry : headers().entrySet()) { for (String value : entry.getValue()) { list.add(new Tuple2<>(entry.getKey(), value)); } } return new Headers(JavaConversions.asScalaBuffer(list)); }
/** * Set the body of the request. * * @param body The body. * @return the modified builder */ protected RequestBuilder body(RequestBody body) { if (body == null || body.as(Object.class) == null) { // assume null signifies no body; RequestBody is a wrapper for the actual body content headers(getHeaders().remove(HeaderNames.CONTENT_LENGTH).remove(HeaderNames.TRANSFER_ENCODING)); } else { if (!getHeaders().get(HeaderNames.TRANSFER_ENCODING).isPresent()) { final MultipartFormData<?> multipartFormData = body.asMultipartFormData(); if (multipartFormData != null) { header(HeaderNames.CONTENT_LENGTH, Long.toString(calcMultipartFormDataBodyLength(multipartFormData))); } else { int length = body.asBytes().length(); header(HeaderNames.CONTENT_LENGTH, Integer.toString(length)); } } } req = req.withBody(body); return this; }
/** * Set the body of the request. * * @param body The body. * @return the modified builder */ protected RequestBuilder body(RequestBody body) { if (body == null || body.as(Object.class) == null) { // assume null signifies no body; RequestBody is a wrapper for the actual body content headers(getHeaders().remove(HeaderNames.CONTENT_LENGTH).remove(HeaderNames.TRANSFER_ENCODING)); } else { if (!getHeaders().get(HeaderNames.TRANSFER_ENCODING).isPresent()) { final MultipartFormData<?> multipartFormData = body.asMultipartFormData(); if (multipartFormData != null) { header(HeaderNames.CONTENT_LENGTH, Long.toString(calcMultipartFormDataBodyLength(multipartFormData))); } else { int length = body.asBytes().length(); header(HeaderNames.CONTENT_LENGTH, Integer.toString(length)); } } } req = req.withBody(body); return this; }
/** * Set the body of the request. * * @param body The body. * @return the modified builder */ protected RequestBuilder body(RequestBody body) { if (body == null || body.as(Object.class) == null) { // assume null signifies no body; RequestBody is a wrapper for the actual body content headers(getHeaders().remove(HeaderNames.CONTENT_LENGTH).remove(HeaderNames.TRANSFER_ENCODING)); } else { if (!getHeaders().get(HeaderNames.TRANSFER_ENCODING).isPresent()) { final MultipartFormData<?> multipartFormData = body.asMultipartFormData(); if (multipartFormData != null) { header(HeaderNames.CONTENT_LENGTH, Long.toString(calcMultipartFormDataBodyLength(multipartFormData))); } else { int length = body.asBytes().length(); header(HeaderNames.CONTENT_LENGTH, Integer.toString(length)); } } } req = req.withBody(body); return this; }
/** * @param key the key for in the header * @param value the value (one) associated with the key * @return the builder instance */ public RequestBuilder header(String key, String value) { return this.headers(getHeaders().addHeader(key, value)); }
/** * @param key the key for in the header * @param values the values associated with the key * @return the builder instance */ public RequestBuilder header(String key, List<String> values) { return this.headers(getHeaders().addHeader(key, values)); }
/** * @param key the key for in the header * @param values the values associated with the key * @return the builder instance */ public RequestBuilder header(String key, List<String> values) { return this.headers(getHeaders().addHeader(key, values)); }
/** * @param key the key for in the header * @param value the value (one) associated with the key * @return the builder instance */ public RequestBuilder header(String key, String value) { return this.headers(getHeaders().addHeader(key, value)); }
/** * @param key the key for in the header * @param value the value (one) associated with the key * @return the builder instance */ public RequestBuilder header(String key, String value) { return this.headers(getHeaders().addHeader(key, value)); }
/** * @param key the key for in the header * @param values the values associated with the key * @return the builder instance */ public RequestBuilder header(String key, List<String> values) { return this.headers(getHeaders().addHeader(key, values)); }