* Fixes #2117 - Allow to configure HttpClient default request Content-Type. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
parent
65101b776b
commit
0b3a276a9b
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue