Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-issuemaster opened this issue Jul 13, 2015 · 5 comments
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Jul 13, 2015

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:

  • #22120 Consistent handling of null header values in HttpHeaders

Referenced from: commits de6bbe7

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 13, 2015

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?

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 13, 2015

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.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 13, 2015

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.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 13, 2015

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);
}
@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jul 14, 2015

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.