-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Fixes #4808 - Review HttpClient Request header APIs. #4845
Fixes #4808 - Review HttpClient Request header APIs. #4845
Conversation
Introduced: * Request Request.headers(Consumer<HttpFields.Mutable>). This allows applications to modify the headers, and chain calls. It also delegates the precise semantic of put/add/remove/clear to HttpFields, so there is no API duplication. * HttpRequest.header(HttpField) to efficiently add fields while normalizing the request (only used in implementation). * HttpResponse.header(HttpField) to efficiently add fields while parsing the response (only used in implementation). This pairs with HttpResponse.trailer(HttpField). * HttpResponse.headers(Consumer<HttpFields.Mutable>) to modify the fields after they have been populated (only used in tests). Removed: * Request.[set,add,put,remove], replaced by headers(Consumer<HttpFields.Mutable>). Deprecated: * Request.header(String, String) * Request.header(HttpHeader, String) Both replaced by headers(Consumer<HttpFields.Mutable>) with clearer semantic for add/put/remove. All the rest is code cleanup to remove the usage of the deprecated header() methods. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Fixed test failures. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
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.
I really like the overall idea of concentrating all the HTTP field modification API into a single class, but it should be pushed to its full extent then: only have one single way to mutate HTTP fields: the lambda-taking mutating method headers()
.
This would have the extra bonus of making it cheap to extend the API with nice helper method (addIfAbsent
, addIfNotNull
...) that would make calling the lambda-taking mutating method very elegant to use.
jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java
Outdated
Show resolved
Hide resolved
jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java
Outdated
Show resolved
Hide resolved
jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java
Outdated
Show resolved
Hide resolved
jetty-client/src/main/java/org/eclipse/jetty/client/HttpReceiver.java
Outdated
Show resolved
Hide resolved
jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyTLSServerTest.java
Show resolved
Hide resolved
jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ForwardProxyTLSServerTest.java
Show resolved
Hide resolved
...test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DuplicateCookieTest.java
Show resolved
Hide resolved
...test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DuplicateCookieTest.java
Show resolved
Hide resolved
...test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DuplicateCookieTest.java
Show resolved
Hide resolved
Is the new That would allow someone to remove/change a header that is added by other processes in the request before it's sent. |
Will you update the client documentation in a future commit? |
@joakime the lambda is invoke immediately. |
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.
LGTM
Updates after review. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Introduced:
Request Request.headers(Consumer<HttpFields.Mutable>).
This allows applications to modify the headers, and chain calls.
It also delegates the precise semantic of put/add/remove/clear to HttpFields, so there is no API duplication.
HttpRequest.header(HttpField) to efficiently add fields while normalizing the request (only used in implementation).
HttpResponse.header(HttpField) to efficiently add fields while parsing the response (only used in implementation).
This pairs with HttpResponse.trailer(HttpField).
HttpResponse.headers(Consumer<HttpFields.Mutable>) to modify the fields after they have been populated (only used in tests).
Removed:
Deprecated:
Both replaced by headers(Consumer<HttpFields.Mutable>) with clearer semantic for add/put/remove.
All the rest is code cleanup to remove the usage of the deprecated header() methods.
Signed-off-by: Simone Bordet simone.bordet@gmail.com