akka-http
akka-http copied to clipboard
empty Uri fragment ignored
The Uri.withFragment
function does not allow one to set an empty fragment, which is allowed by the IETF spec I believe, and by the Uri constructor, as shown:
import akka.http.scaladsl.model.Uri
import Uri.*
scala> val good = Uri("https",Authority(Host("example.com")),Path./("doc"),None,Some(""))
val good: akka.http.scaladsl.model.Uri = https://example.com/doc#
scala> val noFrag = Uri("https",Authority(Host("example.com")),Path./("doc"),None,None)
val noFrag: akka.http.scaladsl.model.Uri = https://example.com/doc
scala> noFrag.withFragment("")
val res3: akka.http.scaladsl.model.Uri = https://example.com/doc
Interesting, thanks, @bblfish. I guess it doesn't really matter in the context of Akka HTTP as fragments are never send through the network. I would be fine with changing the behavior, since I didn't find a reason in RFC 3986 that would specify that empty fragment and no fragment should be treated equally.
Thanks. Empty Hash URIs are found in the wild in the RDF community (which is how I just noticed). We have an implementation of banana-rdf called Plantain, that uses akka Uri for that data structure in our RDF graphs. It kind of helps to have the same data structure in both, as it avoids translating between the different versions all the time.
I think fragments can get sent through the network, in case of HTTP redirects.
I think fragments can get sent through the network, in case of HTTP redirects.
Do you have RFC spec text on that @strelec ?
See this, there is reference to the spec:
https://stackoverflow.com/questions/2286402/url-fragment-and-302-redirects
Here the section that is referenced: https://www.rfc-editor.org/rfc/rfc7231#section-7.1.2
Thanks for that pointer. It makes complete sense that that is possible to return URIs with hashes in responses.