[ 
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:

{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")


  was:
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:

{{
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}
}}

ContentType.create calls a InputStreamEntity constructor:

{{
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}
        }
    }
}}


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:
> {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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to