hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oleg Kalnichevski (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 11:27:21 GMT

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

Oleg Kalnichevski updated HTTPCORE-423:
---------------------------------------
    Priority: Minor  (was: Major)

bq. - Never call toString() in *REAL* code, only for debugging

I have to disgree with this statement. There are enough examples of #toString being used in
productive code

https://docs.oracle.com/javase/7/docs/api/java/io/StringWriter.html#toString()

bq. - the method return "null" (not the null value of the pointer but a string of 4 chars
containing "null")

This is clearly a bug though minor in my opinion.

Oleg

> 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
>            Priority: Minor
>
> 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:
> {code:title=org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.java|borderStyle=solid}
> 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}
> {code}
> ContentType.create() calls a InputStreamEntity constructor:
> {code:title= org.apache.http.entity.InputStreamEntity.java|borderStyle=solid}
> 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}
>         }
>     }
> {code}
> 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