Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-1671

RequestDefaultHeaders should only be set if the header hasn't already been set

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 5.0 Alpha1
    • HttpClient (classic)
    • None

    Description

      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:

      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
      

      A simple fix would be to add the following code snippet:

      if(!request.containsHeader(defHeader.getName)) {
          request.addHeader(defHeader);
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            sdavids Steve Davids
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: