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

Oleg Kalnichevski resolved HTTPCLIENT-1304.
-------------------------------------------

    Resolution: Invalid
    
> SystemDefaultHttpClient discards Headers set on the request
> -----------------------------------------------------------
>
>                 Key: HTTPCLIENT-1304
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1304
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.2.3
>            Reporter: Denis Carniel
>
> If a HttpUriRequest has headers defined using the "setHeader" / "addHeader" 
> methods, those headers are properly sent when the request is executed through 
> a DefaultHttpClient but are discarded when using a SystemDefaultHttpClient.
> As this does not seem to be an expected behaviour it is likely a bug, and a 
> nasty one as the link between the HttpClient implementation and headers 
> processing isn't obvious.
> Folowing the first comment, here is the piece of code I used for my tests 
> (see the point is to add the "Proxy-Authentication" but I tried changing the 
> name and the same happened):
>       public String getThroughHTTPClient( String urlToRead ) {
>               String result = null;
>               
>               HttpUriRequest request = new HttpGet( urlToRead );
>               if( request != null ) {
>                       DefaultHttpClient client = new 
> SystemDefaultHttpClient(); // DefaultHttpClient();
>                       String proxyUser = System.getProperty( "http.proxyUser" 
> );
>                       if ( StringUtils.isNotEmpty( proxyUser ) ) {
>                               String proxyAuthCredentials = proxyUser + ":" + 
> System.getProperty( "http.proxyPassword" );
>                               String base64Credentials = 
> Base64.encodeBase64String( proxyAuthCredentials.getBytes( ) );
>                               request.setHeader( "Proxy-Authentication", 
> "Basic " + base64Credentials );
>                               System.out.println( "Basic " + 
> Base64.encodeBase64String( proxyAuthCredentials.getBytes() ) );
>                       }
>                       try {
>                               HttpResponse response = client.execute(request);
>                               result = IOUtils.toString( 
> response.getEntity().getContent() );
>                       } catch ( ClientProtocolException e ) {
>                               System.err.println( "Unable to process HTTP 
> request." );
>                               e.printStackTrace();
>                       } catch ( IOException e ) {
>                               System.err.println( "Unable to process HTTP 
> request." );
>                               e.printStackTrace();
>                       } finally {
>                               client.getConnectionManager().shutdown();
>                       }                       
>               }
>               
>               return result;
>       }
> I could see that the sent headers were different when changing the HttpClient 
> implementation by turning on header logging.

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

Reply via email to