Java Code Examples for org.asynchttpclient.RequestBuilder#setHeader()

The following examples show how to use org.asynchttpclient.RequestBuilder#setHeader() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsyncHttpRequest.java    From junit-servers with MIT License 5 votes vote down vote up
/**
 * Add body entity to the final HTTP request.
 *
 * @param builder The pending HTTP request.
 * @see RequestBuilder#addFormParam(String, String)
 * @see RequestBuilder#setBody(String)
 */
private void handleBody(RequestBuilder builder) throws IOException {
	if (!hasBody()) {
		log.debug("HTTP Request does not have body, skip.");
		return;
	}

	log.debug("Set body to current request builder using: {}", body);
	builder.setBody(body.getBody());

	if (body.getContentType() != null) {
		builder.setHeader("Content-Type", body.getContentType());
	}
}
 
Example 2
Source File: Zendesk.java    From zendesk-java-client with Apache License 2.0 5 votes vote down vote up
public ArticleAttachments createUploadArticle(long articleId, File file, boolean inline) throws IOException {
RequestBuilder builder = reqBuilder("POST", tmpl("/help_center/articles/{id}/attachments.json").set("id", articleId).toString());
    builder.setHeader("Content-Type", "multipart/form-data");

    if (inline)
        builder.addBodyPart(new StringPart("inline", "true"));

  builder.addBodyPart(
        new FilePart("file", file, "application/octet-stream", StandardCharsets.UTF_8, file.getName()));
    final Request req = builder.build();
    return complete(submit(req, handle(ArticleAttachments.class, "article_attachment")));
}
 
Example 3
Source File: AsyncHttpRequest.java    From junit-servers with MIT License 2 votes vote down vote up
/**
 * Add headers to the final HTTP request.
 *
 * @param builder The pending HTTP request.
 * @see RequestBuilder#addHeader(CharSequence, String)
 */
private void handleHeaders(RequestBuilder builder) {
	for (HttpHeader header : headers.values()) {
		builder.setHeader(header.getName(), header.getValues());
	}
}