Skip to content

SimpleClientHttpRequestFactory: headers with null values should be sent as empty Strings [SPR-13225] #17816

Closed

Description

@spring-projects-issues

Anatoly Deyneka opened SPR-13225 and commented

RestTemplate+SimpleClientHttpRequestFactory:
All headers with null values are sent without colon.
Such requests are rejected by HAProxy(<BADREQ>).
BTW it's correctly processed in HttpComponentsClientHttpRequestFactory

HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.set("some-header", null);
HttpEntity<byte[]> entity = new HttpEntity<>(requestHeaders);
restTemplate.exchange(url, HttpMethod.GET, entity, SomeResponse.class);

Affects: 4.1.6

Issue Links:

Referenced from: commits de6bbe7

Activity

  1. spring-projects-issues commented on Jul 13, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    I can see that a null header value is sent as an empty String with HttpComponentsClientHttpRequestFactory while the header is not sent at all with SimpleClientHttpRequestFactory. In both cases, the request is processed successfully.

    For the record HttpComponentsClientHttpRequestFactory delegates to Apache HTTP components while SimpleClientHttpRequestFactory delegates to the JDK infrastructure (HttpURLConnection typically). The inconsistency I can see lies there anyway.

    Since both requests are processed successfully for me, can you please clarify what you consider to be a bug?

  2. spring-projects-issues commented on Jul 13, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Anatoly Deyneka commented

    headers are sent with SimpleClientHttpRequestFactory.
    I caught traffic, so it looks like:
    GET url HTTP/1.1
    Accept: application/json
    some-header
    User-Agent: Java/1.7.0_60
    Host: host
    Connection: keep-alive

    As you see there is no colon for the header with null value. It's processed in tomcat-server but rejected by HAProxy.
    If you have difficulties with reproducing I can provide exact code.

  3. spring-projects-issues commented on Jul 13, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    The only thing I can think of would be to translate null to an empty String. This would be consistent with what Apache Commons does.

  4. spring-projects-issues commented on Jul 13, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Anatoly Deyneka commented

    Yes, it will fix the problem.

    I would expect fix here:
    SimpleBufferingClientHttpRequest:104

    for (String headerValue : entry.getValue()) {
       connection.addRequestProperty(headerName, headerValue == null ? "" : headerValue);
    }
  5. spring-projects-issues commented on Jul 14, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    Done in master. Could you please give it a try against the next 4.2.0.BUILD-SNAPSHOT? (available in an hour or so). Thanks!

  6. added
    type: enhancement
    in: web
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webtype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions