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-projects-issues opened this issue Jul 13, 2015 · 5 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues 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:

Referenced from: commits de6bbe7

@spring-projects-issues
Copy link
Collaborator Author

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-projects-issues
Copy link
Collaborator Author

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-projects-issues
Copy link
Collaborator Author

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-projects-issues
Copy link
Collaborator Author

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-projects-issues
Copy link
Collaborator Author

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
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants