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
Immutable HttpFields and MetaData #4777
Conversation
Preserve API and usage of HttpFields class while providing a read only interface and immutable implementation. Signed-off-by: Greg Wilkins <gregw@webtide.com>
Use an ArrayList in HttpFields. While slightly slower than the array, it will mostly be used as a builder pattern for an Immutable Signed-off-by: Greg Wilkins <gregw@webtide.com>
First few commits are about creating an immutable |
Fixed exception type. Signed-off-by: Greg Wilkins <gregw@webtide.com>
asImmutable method Signed-off-by: Greg Wilkins <gregw@webtide.com>
Made HttpURIU immutable with a builder pattern. MetaData immutable and working within http module. Signed-off-by: Greg Wilkins <gregw@webtide.com>
@joakime @sbordet @janbartel @lorban @lachlan-roberts I've made |
jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
Outdated
Show resolved
Hide resolved
There's a lack of coherency to quickly figure out if a class is immutable or not or can be made immutable. Maybe we should introduce some form of common pattern for classes that can sometimes be mutable or immutable (like the collections' |
Fixes from review Signed-off-by: Greg Wilkins <gregw@webtide.com>
Passing tests upto and including jetty-server Signed-off-by: Greg Wilkins <gregw@webtide.com>
I've pushed changes that makes tests pass up to and including Currently I've taken 3 different approaches to immutability:
HttpURI newUri = new HttpURI.Builder(oldUri).host(serverName).port(serverPort).normalize().build();
HttpFields newFields = new HttpFields(oldFieldList);
newFields.remove(someHeader);
newFields.put("Header", "replacement value");
HttpFieldList newFieldList = newFields.asImmutable();
One immutable variation I have not used is having an API that is read/write, but the immutable version returns a Also I don't particularly like the Builder pattern being so explicit for HttpURI, so perhaps that could be made a bit cleaning with some utility methods so you could write: HttpURI newUri = HttpURI.copy(oldUri).host(serverName).port(serverPort).normalize().toHttpURI(); Perhaps this approach could also be used to add a builder to HttpFields.copy(oldFields).remove(someHeader).put("Header","replace value").toHttpFields(); This would make HttpFields immutable, so it would not be possible to have code like: HttpFields fields = new HttpFields();
fields.add("Header", "value");
fields.add("Host", "localhost"); This would instead need to be written as HttpFields fields = HttpFields.empty()
.add("Header", "value")
.add("Host", "localhost")
.toHttpFields(); If we decide to go that way, then I think the same approach would work for I may have a fiddle with this.... but I'd really like a bit more feedback before I commit too much more effort. @sbordet specially for h2 and the client. |
For your inspiration, I was thinking about using a pair of marker interfaces that would explicitly state what classes are builders and how to derive a new object from a builder-generated one. Something like:
which would give us:
These interfaces would have minimal added value, but would mostly serve as "marker" interfaces, explicitly letting the programmer know that using some class requires following the common builder / derive pattern. |
Cleanup of HttpURI.Builder API as suggested in PR. Signed-off-by: Greg Wilkins <gregw@webtide.com>
Added builder for MetaData.Request Signed-off-by: Greg Wilkins <gregw@webtide.com>
…ImmutableMetaData
more api fixes Signed-off-by: Greg Wilkins <gregw@webtide.com>
WIP making HttpFiels itself immutable. Currently working up to jetty-servlet. Need to consider if content-length really is meta data and how much and when can we trust it. Signed-off-by: Greg Wilkins <gregw@webtide.com>
WIP Need to consider if content-length really is meta data and how much and when can we trust it. Also need to consider difference between h2 and h1 authority in metadata. Signed-off-by: Greg Wilkins <gregw@webtide.com>
@sbordet can I get a few hours of your time early next week to consider the impact of this on the client and h2. |
jetty-client and jetty-servlet passing tests. Signed-off-by: Greg Wilkins <gregw@webtide.com>
Better align the style of immutability between `HttpFields` and `HttpURI`. They both now have static build() and from() methods, plus Builder and Immutable implementations. Potentially `Builder` could be renamed as `Mutable` Signed-off-by: Greg Wilkins <gregw@webtide.com>
http2-server tests passed Signed-off-by: Greg Wilkins <gregw@webtide.com>
http2-client tests passed Signed-off-by: Greg Wilkins <gregw@webtide.com>
cleann build? Signed-off-by: Greg Wilkins <gregw@webtide.com>
fix Signed-off-by: Greg Wilkins <gregw@webtide.com>
more test fixes Signed-off-by: Greg Wilkins <gregw@webtide.com>
…ImmutableMetaData Signed-off-by: Greg Wilkins <gregw@webtide.com>
review changes Signed-off-by: Greg Wilkins <gregw@webtide.com>
...bsocket-core/src/main/java/org/eclipse/jetty/websocket/core/client/HttpUpgraderOverHTTP.java
Outdated
Show resolved
Hide resolved
...socket-core/src/main/java/org/eclipse/jetty/websocket/core/client/HttpUpgraderOverHTTP2.java
Outdated
Show resolved
Hide resolved
jetty-client/src/main/java/org/eclipse/jetty/client/HttpResponse.java
Outdated
Show resolved
Hide resolved
jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java
Outdated
Show resolved
Hide resolved
.../test/java/org/eclipse/jetty/websocket/core/extensions/PerMessageDeflaterBufferSizeTest.java
Outdated
Show resolved
Hide resolved
...-client/src/main/java/org/eclipse/jetty/websocket/client/impl/JettyClientUpgradeRequest.java
Outdated
Show resolved
Hide resolved
...ent-transport/src/test/java/org/eclipse/jetty/http/client/ProxyWithDynamicTransportTest.java
Outdated
Show resolved
Hide resolved
...ent-transport/src/test/java/org/eclipse/jetty/http/client/ProxyWithDynamicTransportTest.java
Outdated
Show resolved
Hide resolved
changes after review: + less usage of Mutable + more usage of EMPTY + restored fragment handling Signed-off-by: Greg Wilkins <gregw@webtide.com>
changes after review: + less usage of Mutable + less usage of asImmutable Signed-off-by: Greg Wilkins <gregw@webtide.com>
changes after review: + less usage of Mutable Signed-off-by: Greg Wilkins <gregw@webtide.com>
changes after review: + better handling of URI in ContextHandler Signed-off-by: Greg Wilkins <gregw@webtide.com>
changes after review: + downcast in test to access mutable response headers. Signed-off-by: Greg Wilkins <gregw@webtide.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.
Almost there.
jetty-documentation/src/main/java/embedded/client/http2/HTTP2ClientDocs.java
Outdated
Show resolved
Hide resolved
jetty-documentation/src/main/java/embedded/client/http2/HTTP2ClientDocs.java
Outdated
Show resolved
Hide resolved
...socket-core/src/main/java/org/eclipse/jetty/websocket/core/client/HttpUpgraderOverHTTP2.java
Outdated
Show resolved
Hide resolved
...-client/src/main/java/org/eclipse/jetty/websocket/client/impl/JettyClientUpgradeRequest.java
Show resolved
Hide resolved
changes after review: + use put instead of add for one time headers Signed-off-by: Greg Wilkins <gregw@webtide.com>
@sbordet are we there yet? |
...socket-core/src/main/java/org/eclipse/jetty/websocket/core/client/HttpUpgraderOverHTTP2.java
Outdated
Show resolved
Hide resolved
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'm happy with this too.
Last build failed. |
Can you merge in the current |
In Jetty 10, request headers are immutable, see jetty/jetty.project#4777, but we need to remove/hide forwarded headers when they have been used. See gh-27424
Adapt JettyServer to Jetty refactoring jetty/jetty.project#4777 Bug: Issue 317770594 Release-Notes: Update Jetty to 10.0.19 and servlet-api to 4.0.4 Change-Id: I6faa8b8e13b1525120db79b27ff2a72bf8c5f865
Adapt JettyServer to Jetty refactoring jetty/jetty.project#4777 Bug: Issue 317770594 Release-Notes: Update Jetty to 10.0.19 and servlet-api to 4.0.4 Change-Id: I6faa8b8e13b1525120db79b27ff2a72bf8c5f865
Adapt JettyServer to Jetty refactoring jetty/jetty.project#4777 Bug: Issue 317770594 Release-Notes: Update Jetty to 10.0.19 and servlet-api to 4.0.4 Change-Id: I6faa8b8e13b1525120db79b27ff2a72bf8c5f865
This is an experimental branch to see the impact of making
MetaData
immutable. This is currently against 10, but may be for a 10.1 or later version.