Caddy: redir doesn't work with with URL fragments

Created on 15 May 2018  路  5Comments  路  Source: caddyserver/caddy

1. What version of Caddy are you using (caddy -version)?

0.11.0

2. What are you trying to do?

Redirect from source URL like http://foo/hello to URL like http://bar/#baz/hello

3. What is your entire Caddyfile?

localhost:80 {
    redir / http://example.com/#foo{uri} 302
}

5. Please paste any relevant HTTP request(s) here.

$ curl -I http://localhost:9000/hello

6. What did you expect to see?

...
Location: http://example.com/#foo/hello
...

7. What did you see instead (give full error messages and/or log)?

HTTP/1.1 302 Found
Content-Type: text/html; charset=utf-8
Location: http://example.com/                               <----------
Server: Caddy
Date: Tue, 15 May 2018 13:09:46 GMT

Most helpful comment

Thank you for the issue.

This is correct behavior. The fragment should not even be sent to the server let alone dealt with by the server.

An interesting brief explanation is on Stackoverflow here

I think I will close this as it is by design.

All 5 comments

Thank you for the issue.

This is correct behavior. The fragment should not even be sent to the server let alone dealt with by the server.

An interesting brief explanation is on Stackoverflow here

I think I will close this as it is by design.

We could perhaps add a parse error to a redir directive if it includes a # if someone wished to provide a PR.

@tobya I think you misunderstood the issue.

It's not about fragment reaching server, but about server generating response with fragment in Location header. See RFC - https://tools.ietf.org/html/rfc7231#section-7.1.2

I don't have time to look into this more, but we use the Go standard library's Redirect() function for this, so it might be with how they parse the URL: https://golang.org/src/net/http/server.go?s=60163:60228#L1988

I see what you mean now, I'm still unsure where the issue lies though.

There is some discussion about use of fragment in location header in html but still client side

https://greenbytes.de/tech/webdav/draft-ietf-httpbis-p2-semantics-17.html#rfc.section.9.5
https://stackoverflow.com/questions/2286402/url-fragment-and-302-redirects

If we could find an official reference around how this should be handled, we could consider it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kilpatty picture kilpatty  路  3Comments

muhammadmuzzammil1998 picture muhammadmuzzammil1998  路  3Comments

lorddaedra picture lorddaedra  路  3Comments

dafanasiev picture dafanasiev  路  3Comments

ericmdantas picture ericmdantas  路  3Comments