-
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
HttpURI.toURI() does not copy fragment #7750
Comments
It was/is kind of a deliberate bug. Browsers should never send a fragment to the server and as HttpURI is primarily a class used for our server to handle/manipulate URIs, we left the fragment out so that even if some non-browser client sent one, we would drop it and not copy it. This was done more so that we didn't have to think about any consequences of propagating a fragment in server rather than from any hard knowledge of a specific problem. So can you tell us more about your use-case and why you need a fragment in HttpURI? If there us a real usage, then perhaps we can support it. If there is not, then we should at least document that we deliberately drop the fragment. |
@gregw Good to know. I was just going to use it in a Location header from the server side to have the browser automatically scroll to a specific tag, which appears to be accepted by all browsers and in the HTTP spec. I ended up just using specific HttpURI methods instead of HttpURI or URI toString() because it gives more control over the format anyways, but it would be good to at least have a javadoc comment on that method mentioning that it doesn't copy the fragment. |
Just adding information (for others that see this in the future) The HTTP protocol, be it HTTP/1.1 or HTTP/2 (or HTTP/3), basically says that the resource being requested is defined by the ABNF for See:
The scheme-specific URI handling for
|
This issue has been automatically marked as stale because it has been a |
* HttpURI toURI passes all info Fix #11465 and #7750 HttpURI.toURI user and fragment are retained. Use to URI(String) constructor, as all URI constructors will parse the URI anyway. * HttpURI toURI passes all info Fix #11465 and #7750 HttpURI.toURI user and fragment are retained. Use to URI(String) constructor, as all URI constructors will parse the URI anyway.
Jetty version(s)
11.0.7
Java version/vendor
(use: java -version)
Oracle OpenJDK 17 (from jdk.java.net)
OS type/version
Windows 10.
Description
The fragment does not get copied into the URI object, the final parameter in the URI constructor is set to null, even though HttpURI can handle fragments. This is very unexpected, and I assume, a bug.
https://github.com/eclipse/jetty.project/blob/cb127793e5d8b5c5730b964392a9a905ba49191d/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java#L242
How to reproduce?
HttpURI.build(request.getHttpURI()).fragment("a_fragment").toURI().toString()
will produce a URI with no fragment.The text was updated successfully, but these errors were encountered: