-
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
Freeze HttpFields #10339
Freeze HttpFields #10339
Conversation
Currently I have explicit attempts to remove frozen fields throwing ISE. Other options include:
I think I'm leaning to 2) else 1) but maybe 3)... no strong feelings. Thoughts? |
@sbordet I've implemented this with a specific field type like you suggested. |
The changes from PR #10310 have been merged, lets merge those into this PR and continue the reset behaviors here. |
# Conflicts: # jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java # jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java
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.
Do we have a testcase where the Server
and/or X-Powered-By
headers are set by a handler to something different?
What about apps that want to set the Date
header? can they?
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
Show resolved
Hide resolved
@@ -1185,7 +1184,7 @@ public void setStatus(int code) | |||
} | |||
|
|||
@Override | |||
public HttpFields.Mutable getHeaders() | |||
public ResponseHttpFields getHeaders() |
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.
Why did this need to be changed?
I cannot see any unique methods that only ResponseHttpFields implement
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.
This was for the previous implementation that did freeze/thaw. It is no longer needed so I will revert.
Not explicitly, but it is the same case as the Date header below
We do have tests that explicitly set the Date header and the ResponseTest also checks that persistent headers can be modified with iterator sets. The original change treated these fields as immutable, which was incorrect and I changed to make sure only that they cannot be deleted, but they can be modified (if the HttpFields itself is in a mutable state). I'll add a test for a put of SERVER. |
i.remove(); | ||
_current = null; |
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.
You should also throw ISE when _current
is null according to the Iterator.remove()
javadoc.
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.
The i.remove() on the previous line will do that. But I will add an explicit check
} | ||
|
||
@Override | ||
public void remove() | ||
{ | ||
if (_committed.get()) | ||
throw new UnsupportedOperationException("Read Only"); | ||
if (isPersistent(_current)) | ||
throw new IllegalStateException("Persistent field"); |
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.
My interpretation of the Iterator.remove()
javadoc makes me think UnsupportedOperationException
should be thrown here.
i.remove(); | ||
_current = null; |
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.
You should also throw ISE when _current
is null according to the Iterator.remove()
javadoc.
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 believe the i.remove() call above will do that. I can explicitly do the check if you really want ?
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/ResponseHttpFields.java
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/ResponseHttpFields.java
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/ResponseHttpFields.java
Show resolved
Hide resolved
jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java
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.
See also my comments about this PR in #10340.
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/internal/ResponseHttpFields.java
Show resolved
Hide resolved
jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java
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'd like to add a testcase all the way up in ee10-servlets to verify the behavior up there too.
Mind if I add it to this branch?
was approved in #10340 and only nit fixed afterwards
Use the core response HttpFields directly as the ee9 response headers to avoid copy and retain persistent field behaviour. Added EE9 test to show that Persistent fields can be modified Updated fix for #10339 so that persistent fields revert to original values after a clear operation
Use the core response HttpFields directly as the ee9 response headers to avoid copy and retain persistent field behaviour. Fix #10416 EE9 Response headers Added EE9 test to show that Persistent fields can be modified Updated fix for #10339 so that persistent fields revert to original values after a clear operation
Provide a mechanism to freeze a HTTP response headers so that container provided headers are not lost in a reset. From question in #10310