hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Davids (JIRA)" <j...@apache.org>
Subject [jira] [Created] (HTTPCLIENT-1671) RequestDefaultHeaders should only be set if the header hasn't already been set
Date Tue, 28 Jul 2015 16:23:05 GMT
Steve Davids created HTTPCLIENT-1671:
----------------------------------------

             Summary: RequestDefaultHeaders should only be set if the header hasn't already
been set
                 Key: HTTPCLIENT-1671
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1671
             Project: HttpComponents HttpClient
          Issue Type: Improvement
          Components: HttpClient
            Reporter: Steve Davids


The name implies that default header values will be applied to the request which generally
means that if the request doesn't specify a header value then the default is applied. For
example:

{code}
defaultHeaderValue = ["Accept": "application/json"]

httpClient.execute(new HttpGet(url)); //header should be application/json

HttpGet get = new HttpGet(url);
get.setHeader("Accept", "application/xml");
httpClient.execute(get); //header should be application/xml, *not* application/xml, application/json
{code}

A simple fix would be to add the following code snippet:
{code}
if(!request.containsHeader(defHeader.getName)) {
    request.addHeader(defHeader);
}
{code}



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