/** * 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; }