-
Notifications
You must be signed in to change notification settings - Fork 536
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
[2678] Send multiple headers for url-encoded and multipart-form bodies #2679
base: master
Are you sure you want to change the base?
Conversation
8e985f2
to
f4dd014
Compare
for (String headerName : requestHeaders.names()) { | ||
headers.remove(headerName); | ||
} | ||
headers.addAll(requestHeaders); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I do not quite understand why headers are copied twice. See
vertx-web/vertx-web-client/src/main/java/io/vertx/ext/web/client/impl/HttpRequestImpl.java
Line 538 in 2a661ad
void mergeHeaders(RequestOptions options) { |
Without the second copying all tests are also passed. Check test commit ilia1243@f470308
Though I see some activity with this code
I did not remove this part, because do not see the whole picture. Please comment if this can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, adding the request headers again looks redundant. You could replace line 446-451 in the original file with:
for (Map.Entry<String, String> header : multipartForm.headers()) {
requestOptions.putHeader(header.getKey(), header.getValue());
}
That would do (using forEach
here implies creating a lamba on each call and does not bring anything).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @ilia1243 , good stuff
for (String headerName : requestHeaders.names()) { | ||
headers.remove(headerName); | ||
} | ||
headers.addAll(requestHeaders); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, adding the request headers again looks redundant. You could replace line 446-451 in the original file with:
for (Map.Entry<String, String> header : multipartForm.headers()) {
requestOptions.putHeader(header.getKey(), header.getValue());
}
That would do (using forEach
here implies creating a lamba on each call and does not bring anything).
tmp = MultiMap.caseInsensitiveMultiMap(); | ||
options.setHeaders(tmp); | ||
} | ||
MultiMap tmp = checkHeaders(options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering the comments related to HttpContext
you can revert changes in this file.
Motivation:
Multiple headers are not sent with url-encoded and multipart-form bodies.
Solution:
Change resolution of headers in
HttpContext#handleCreateRequest()
. Do not useMultiMap#get()
to copy headers anymore. Instead, copy the entries from the original MultiMap usingMultiMap#addAll(MultiMap)
.Fixes #2678