Fixes #2117 - Allow to configure HttpClient default request Content-Type (#2118)

* Fixes #2117 - Allow to configure HttpClient default request Content-Type.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2018-01-13 10:31:13 +01:00 committed by GitHub
parent 65101b776b
commit 0b3a276a9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -150,6 +150,7 @@ public class HttpClient extends ContainerLifeCycle
private boolean connectBlocking = false;
private String name = getClass().getSimpleName() + "@" + Integer.toHexString(hashCode());
private HttpCompliance httpCompliance = HttpCompliance.RFC7230;
private String defaultRequestContentType = "application/octet-stream";
/**
* Creates a {@link HttpClient} instance that can perform requests to non-TLS destinations only
@ -1086,6 +1087,23 @@ public class HttpClient extends ContainerLifeCycle
this.connectBlocking = connectBlocking;
}
/**
* @return the default content type for request content
*/
@ManagedAttribute("The default content type for request content")
public String getDefaultRequestContentType()
{
return defaultRequestContentType;
}
/**
* @param contentType the default content type for request content
*/
public void setDefaultRequestContentType(String contentType)
{
this.defaultRequestContentType = contentType;
}
/**
* @return the forward proxy configuration
*/

View File

@ -121,9 +121,15 @@ public abstract class HttpConnection implements Connection
if (content instanceof ContentProvider.Typed)
contentType = ((ContentProvider.Typed)content).getContentType();
if (contentType != null)
{
headers.put(HttpHeader.CONTENT_TYPE, contentType);
}
else
headers.put(HttpHeader.CONTENT_TYPE, "application/octet-stream");
{
contentType = getHttpClient().getDefaultRequestContentType();
if (contentType != null)
headers.put(HttpHeader.CONTENT_TYPE, contentType);
}
}
long contentLength = content.getLength();
if (contentLength >= 0)