hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jean-Eric Cuendet (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (HTTPCORE-423) Content-Type is wrongly handled in case of empty body during a PUT
Date Thu, 09 Jun 2016 09:24:21 GMT

     [ https://issues.apache.org/jira/browse/HTTPCORE-423?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Jean-Eric Cuendet updated HTTPCORE-423:
---------------------------------------
    Description: 
We use Zuul to forward requests.

We have a PUT without body, in this case the content-type is null,  and content-length = 0
But in the below code, we get the content-type from the request ans handle it badly:

{{monospaced}}
class org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter
method private HttpResponse forward(HttpClient httpclient, String verb, String uri,
			HttpServletRequest request, MultiValueMap<String, String> headers,
			MultiValueMap<String, String> params, InputStream requestEntity)
					throws Exception {
		Map<String, Object> info = this.helper.debug(verb, uri, headers, params,
				requestEntity);
		URL host = RequestContext.getCurrentContext().getRouteHost();
		HttpHost httpHost = getHttpHost(host);
		uri = StringUtils.cleanPath((host.getPath() + uri).replaceAll("/{2,}", "/"));
		HttpRequest httpRequest;
		int contentLength = request.getContentLength();
{color:red}
		InputStreamEntity entity = new InputStreamEntity(requestEntity, contentLength,
				ContentType.create(request.getContentType()));
{color:red}
{{monospaced}}

ContentType.create calls a InputStreamEntity constructor:

{{monospaced}}
public InputStreamEntity(final InputStream instream, final long length, final ContentType
contentType) {
        super();
        this.content = Args.notNull(instream, "Source input stream");
        this.length = length;
        if (contentType != null) {
{color:red}
            setContentType(contentType.toString());
{color:red}
        }
    }
{{monospaced}}

toString() is called on contentType which has a null mimeType member.

This is wrong:
- Never call toString() in *REAL* code, only for debugging
- the method return "null" (not the null value of the pointer but a string of 4 chars containing
"null")


> Content-Type is wrongly handled in case of empty body during a PUT
> ------------------------------------------------------------------
>
>                 Key: HTTPCORE-423
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-423
>             Project: HttpComponents HttpCore
>          Issue Type: Bug
>          Components: HttpCore
>    Affects Versions: 4.4.4
>            Reporter: Jean-Eric Cuendet
>
> We use Zuul to forward requests.
> We have a PUT without body, in this case the content-type is null,  and content-length
= 0
> But in the below code, we get the content-type from the request ans handle it badly:
> {{monospaced}}
> class org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter
> method private HttpResponse forward(HttpClient httpclient, String verb, String uri,
> 			HttpServletRequest request, MultiValueMap<String, String> headers,
> 			MultiValueMap<String, String> params, InputStream requestEntity)
> 					throws Exception {
> 		Map<String, Object> info = this.helper.debug(verb, uri, headers, params,
> 				requestEntity);
> 		URL host = RequestContext.getCurrentContext().getRouteHost();
> 		HttpHost httpHost = getHttpHost(host);
> 		uri = StringUtils.cleanPath((host.getPath() + uri).replaceAll("/{2,}", "/"));
> 		HttpRequest httpRequest;
> 		int contentLength = request.getContentLength();
> {color:red}
> 		InputStreamEntity entity = new InputStreamEntity(requestEntity, contentLength,
> 				ContentType.create(request.getContentType()));
> {color:red}
> {{monospaced}}
> ContentType.create calls a InputStreamEntity constructor:
> {{monospaced}}
> public InputStreamEntity(final InputStream instream, final long length, final ContentType
contentType) {
>         super();
>         this.content = Args.notNull(instream, "Source input stream");
>         this.length = length;
>         if (contentType != null) {
> {color:red}
>             setContentType(contentType.toString());
> {color:red}
>         }
>     }
> {{monospaced}}
> toString() is called on contentType which has a null mimeType member.
> This is wrong:
> - Never call toString() in *REAL* code, only for debugging
> - the method return "null" (not the null value of the pointer but a string of 4 chars
containing "null")



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message