You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Alan T Chen (JIRA)" <ji...@apache.org> on 2012/10/25 16:33:12 UTC

[jira] [Created] (HTTPCLIENT-1253) URIBuilder setParameter() method could exceed the http header size.

Alan T Chen created HTTPCLIENT-1253:
---------------------------------------

             Summary: URIBuilder setParameter() method could exceed the http header size.  
                 Key: HTTPCLIENT-1253
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1253
             Project: HttpComponents HttpClient
          Issue Type: Improvement
          Components: HttpClient
    Affects Versions: 4.2.1
            Reporter: Alan T Chen
            Priority: Minor


Maybe the URIBuilder is not designed with POST vs GET in mind so it will construct the form parameters into the header by default.  However, this is an issue when the content exceeds what the header allows.

the following code will cause issues when the length of the parameters exceed the http header.

                // TODO: need to pass in the target host/port
                URIBuilder builder = new URIBuilder();
                builder.setScheme("http").setHost(targetHost).setPort(targetPort).setPath(s);

                Map<String, String> params = getRequestParameters(servletRequest);
                for (String key : params.keySet())
                {
                    String value = params.get(key);

                    builder.setParameter(key, value);
                }

                httpPost = new HttpPost(builder.build());

======== 
I have to fix it by using the httpPost.setEntity() method to ensure the form post will insert all parameters into the body of the http post request instead of the header.

                httpPost = new HttpPost(builder.build());

                Map<String, String> params = getRequestParameters(servletRequest);
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(20);

                // add the params
                for (String key : params.keySet())
                {
                    String value = params.get(key);

                    // only add the http param if both key and value are not null
                    if( key != null && value != null )
                        nameValuePairs.add(new BasicNameValuePair(key, value));
                }

                httpPost.setEntity( new UrlEncodedFormEntity(nameValuePairs) );


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

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


[jira] [Commented] (HTTPCLIENT-1253) URIBuilder setParameter() method could exceed the http header size.

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1253?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13484412#comment-13484412 ] 

Oleg Kalnichevski commented on HTTPCLIENT-1253:
-----------------------------------------------

Alan
URIBuilder is completely HTTP message agnostic. I am not sure I understand what kind of change you are proposing. 

Oleg
                
> URIBuilder setParameter() method could exceed the http header size.  
> ---------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1253
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1253
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>          Components: HttpClient
>    Affects Versions: 4.2.1
>            Reporter: Alan T Chen
>            Priority: Minor
>
> Maybe the URIBuilder is not designed with POST vs GET in mind so it will construct the form parameters into the header by default.  However, this is an issue when the content exceeds what the header allows.
> the following code will cause issues when the length of the parameters exceed the http header.
>                 // TODO: need to pass in the target host/port
>                 URIBuilder builder = new URIBuilder();
>                 builder.setScheme("http").setHost(targetHost).setPort(targetPort).setPath(s);
>                 Map<String, String> params = getRequestParameters(servletRequest);
>                 for (String key : params.keySet())
>                 {
>                     String value = params.get(key);
>                     builder.setParameter(key, value);
>                 }
>                 httpPost = new HttpPost(builder.build());
> ======== 
> I have to fix it by using the httpPost.setEntity() method to ensure the form post will insert all parameters into the body of the http post request instead of the header.
>                 httpPost = new HttpPost(builder.build());
>                 Map<String, String> params = getRequestParameters(servletRequest);
>                 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(20);
>                 // add the params
>                 for (String key : params.keySet())
>                 {
>                     String value = params.get(key);
>                     // only add the http param if both key and value are not null
>                     if( key != null && value != null )
>                         nameValuePairs.add(new BasicNameValuePair(key, value));
>                 }
>                 httpPost.setEntity( new UrlEncodedFormEntity(nameValuePairs) );

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

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


[jira] [Commented] (HTTPCLIENT-1253) URIBuilder setParameter() method could exceed the http header size.

Posted by "Alan T Chen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1253?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13484502#comment-13484502 ] 

Alan T Chen commented on HTTPCLIENT-1253:
-----------------------------------------

Ok, I will checkout the RequestBuilder class... 


                
> URIBuilder setParameter() method could exceed the http header size.  
> ---------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1253
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1253
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>          Components: HttpClient
>    Affects Versions: 4.2.1
>            Reporter: Alan T Chen
>            Priority: Minor
>
> Maybe the URIBuilder is not designed with POST vs GET in mind so it will construct the form parameters into the header by default.  However, this is an issue when the content exceeds what the header allows.
> the following code will cause issues when the length of the parameters exceed the http header.
>                 // TODO: need to pass in the target host/port
>                 URIBuilder builder = new URIBuilder();
>                 builder.setScheme("http").setHost(targetHost).setPort(targetPort).setPath(s);
>                 Map<String, String> params = getRequestParameters(servletRequest);
>                 for (String key : params.keySet())
>                 {
>                     String value = params.get(key);
>                     builder.setParameter(key, value);
>                 }
>                 httpPost = new HttpPost(builder.build());
> ======== 
> I have to fix it by using the httpPost.setEntity() method to ensure the form post will insert all parameters into the body of the http post request instead of the header.
>                 httpPost = new HttpPost(builder.build());
>                 Map<String, String> params = getRequestParameters(servletRequest);
>                 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(20);
>                 // add the params
>                 for (String key : params.keySet())
>                 {
>                     String value = params.get(key);
>                     // only add the http param if both key and value are not null
>                     if( key != null && value != null )
>                         nameValuePairs.add(new BasicNameValuePair(key, value));
>                 }
>                 httpPost.setEntity( new UrlEncodedFormEntity(nameValuePairs) );

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

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


[jira] [Commented] (HTTPCLIENT-1253) URIBuilder setParameter() method could exceed the http header size.

Posted by "Alan T Chen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1253?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13484471#comment-13484471 ] 

Alan T Chen commented on HTTPCLIENT-1253:
-----------------------------------------

Being http POST/GET agnostic is ok but while using in the context of a POST request, all of the parameters were redered as part of the http header and it could be confusing to think the params within a form post are not inside the BODY.

httpPost = new HttpPost(builder.build());



                
> URIBuilder setParameter() method could exceed the http header size.  
> ---------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1253
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1253
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>          Components: HttpClient
>    Affects Versions: 4.2.1
>            Reporter: Alan T Chen
>            Priority: Minor
>
> Maybe the URIBuilder is not designed with POST vs GET in mind so it will construct the form parameters into the header by default.  However, this is an issue when the content exceeds what the header allows.
> the following code will cause issues when the length of the parameters exceed the http header.
>                 // TODO: need to pass in the target host/port
>                 URIBuilder builder = new URIBuilder();
>                 builder.setScheme("http").setHost(targetHost).setPort(targetPort).setPath(s);
>                 Map<String, String> params = getRequestParameters(servletRequest);
>                 for (String key : params.keySet())
>                 {
>                     String value = params.get(key);
>                     builder.setParameter(key, value);
>                 }
>                 httpPost = new HttpPost(builder.build());
> ======== 
> I have to fix it by using the httpPost.setEntity() method to ensure the form post will insert all parameters into the body of the http post request instead of the header.
>                 httpPost = new HttpPost(builder.build());
>                 Map<String, String> params = getRequestParameters(servletRequest);
>                 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(20);
>                 // add the params
>                 for (String key : params.keySet())
>                 {
>                     String value = params.get(key);
>                     // only add the http param if both key and value are not null
>                     if( key != null && value != null )
>                         nameValuePairs.add(new BasicNameValuePair(key, value));
>                 }
>                 httpPost.setEntity( new UrlEncodedFormEntity(nameValuePairs) );

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

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


[jira] [Updated] (HTTPCLIENT-1253) URIBuilder setParameter() method could exceed the http header size.

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-1253?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski updated HTTPCLIENT-1253:
------------------------------------------

    Fix Version/s: 4.3 Final
    
> URIBuilder setParameter() method could exceed the http header size.  
> ---------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1253
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1253
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>          Components: HttpClient
>    Affects Versions: 4.2.1
>            Reporter: Alan T Chen
>            Priority: Minor
>             Fix For: 4.3 Final
>
>
> Maybe the URIBuilder is not designed with POST vs GET in mind so it will construct the form parameters into the header by default.  However, this is an issue when the content exceeds what the header allows.
> the following code will cause issues when the length of the parameters exceed the http header.
>                 // TODO: need to pass in the target host/port
>                 URIBuilder builder = new URIBuilder();
>                 builder.setScheme("http").setHost(targetHost).setPort(targetPort).setPath(s);
>                 Map<String, String> params = getRequestParameters(servletRequest);
>                 for (String key : params.keySet())
>                 {
>                     String value = params.get(key);
>                     builder.setParameter(key, value);
>                 }
>                 httpPost = new HttpPost(builder.build());
> ======== 
> I have to fix it by using the httpPost.setEntity() method to ensure the form post will insert all parameters into the body of the http post request instead of the header.
>                 httpPost = new HttpPost(builder.build());
>                 Map<String, String> params = getRequestParameters(servletRequest);
>                 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(20);
>                 // add the params
>                 for (String key : params.keySet())
>                 {
>                     String value = params.get(key);
>                     // only add the http param if both key and value are not null
>                     if( key != null && value != null )
>                         nameValuePairs.add(new BasicNameValuePair(key, value));
>                 }
>                 httpPost.setEntity( new UrlEncodedFormEntity(nameValuePairs) );

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

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


[jira] [Commented] (HTTPCLIENT-1253) URIBuilder setParameter() method could exceed the http header size.

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1253?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13484495#comment-13484495 ] 

Oleg Kalnichevski commented on HTTPCLIENT-1253:
-----------------------------------------------

Bizarre. On the contrary, I find the idea of request URI parameters getting copied into request body confusing and utterly illogical. There is more to POST method than submitting URL encoded HTML forms. 

Anyhow, there is a new class in the 4.3 branch called RequestBuilder [1]. The builder currently takes an immutable URI as input. It can be changed to accept URI elements individually and assemble them differently depending on particular composition of the request. In case of a POST method with no explicitly body the builder could pack request parameters into body instead of URI. 

Feel free to contribute a patch.

Oleg

[1] http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/RequestBuilder.java
                
> URIBuilder setParameter() method could exceed the http header size.  
> ---------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1253
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1253
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>          Components: HttpClient
>    Affects Versions: 4.2.1
>            Reporter: Alan T Chen
>            Priority: Minor
>
> Maybe the URIBuilder is not designed with POST vs GET in mind so it will construct the form parameters into the header by default.  However, this is an issue when the content exceeds what the header allows.
> the following code will cause issues when the length of the parameters exceed the http header.
>                 // TODO: need to pass in the target host/port
>                 URIBuilder builder = new URIBuilder();
>                 builder.setScheme("http").setHost(targetHost).setPort(targetPort).setPath(s);
>                 Map<String, String> params = getRequestParameters(servletRequest);
>                 for (String key : params.keySet())
>                 {
>                     String value = params.get(key);
>                     builder.setParameter(key, value);
>                 }
>                 httpPost = new HttpPost(builder.build());
> ======== 
> I have to fix it by using the httpPost.setEntity() method to ensure the form post will insert all parameters into the body of the http post request instead of the header.
>                 httpPost = new HttpPost(builder.build());
>                 Map<String, String> params = getRequestParameters(servletRequest);
>                 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(20);
>                 // add the params
>                 for (String key : params.keySet())
>                 {
>                     String value = params.get(key);
>                     // only add the http param if both key and value are not null
>                     if( key != null && value != null )
>                         nameValuePairs.add(new BasicNameValuePair(key, value));
>                 }
>                 httpPost.setEntity( new UrlEncodedFormEntity(nameValuePairs) );

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

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