akka-http icon indicating copy to clipboard operation
akka-http copied to clipboard

empty Uri fragment ignored

Open bblfish opened this issue 3 years ago • 7 comments

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

bblfish avatar Jun 29 '21 11:06 bblfish

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.

jrudolph avatar Jun 29 '21 11:06 jrudolph

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.

bblfish avatar Jun 29 '21 12:06 bblfish

I think fragments can get sent through the network, in case of HTTP redirects.

strelec avatar Sep 14 '21 19:09 strelec

I think fragments can get sent through the network, in case of HTTP redirects.

Do you have RFC spec text on that @strelec ?

bblfish avatar Nov 02 '21 12:11 bblfish

See this, there is reference to the spec:

https://stackoverflow.com/questions/2286402/url-fragment-and-302-redirects

strelec avatar Nov 02 '21 18:11 strelec

Here the section that is referenced: https://www.rfc-editor.org/rfc/rfc7231#section-7.1.2

jrudolph avatar Nov 03 '21 08:11 jrudolph

Thanks for that pointer. It makes complete sense that that is possible to return URIs with hashes in responses.

bblfish avatar Nov 03 '21 08:11 bblfish