HTTPResponse converts all header names to lower case

Issue #131 resolved
Pétur Runólfsson created an issue

The HTTPResponse class converts all header names to lower case. For example, setLocation() now creates a header named "location" where before it would create a header named "Location". This has changed sometime between versions 4.8 and 4.13.

Although HTTP header names are case-insensitive, use of mixed case is traditional, so it should be preserved if possible.

This seems to be due to the use of HashMap<String, String> to store the headers. For a case-preserving but case-insensitive map, new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER) is one solution.

public class HTTPResponseTest {
    @Test
    public void shouldBeCasePreserving() {
        HTTPResponse response = new HTTPResponse(302);
        response.setHeader("Location", "http://example.org");

        assertEquals("Location", response.getHeaders().keySet().iterator().next());
    }
}

Comments (3)

  1. Connect2id OSS

    Thanks for spotting this. We did a significant refactoring of the HTTP wrappers and this may have been a result of this.

  2. Log in to comment