Skip to content
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

DNS entry broken with endless redirect loop #1233

Closed
2 tasks done
Luzifer opened this issue May 16, 2015 · 16 comments
Closed
2 tasks done

DNS entry broken with endless redirect loop #1233

Luzifer opened this issue May 16, 2015 · 16 comments

Comments

@Luzifer
Copy link
Member

Luzifer commented May 16, 2015

As an IPFS user wanting to host a static website in IPFS I'd set an TXT and an A record to my domain to point to an IPFS endpoint and having an hash containing the website itself like explained in #760.

Expected behavior

When I open the website I expect to get it served.

Actual behavior

I'm trapped in an endless redirect loop

Version

Latest Docker-Image from jbenet/go-ipfs

Steps to reproduce

# dig any swagger.luzifer.io

; <<>> DiG 9.8.3-P1 <<>> any swagger.luzifer.io
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46065
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;swagger.luzifer.io.        IN  ANY

;; ANSWER SECTION:
swagger.luzifer.io. 576 IN  TXT "QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA"
swagger.luzifer.io. 576 IN  A   188.40.126.69

;; Query time: 2 msec
;; SERVER: 10.228.0.254#53(10.228.0.254)
;; WHEN: Sat May 16 03:21:06 2015
;; MSG SIZE  rcvd: 111

# curl -I swagger.luzifer.io
HTTP/1.1 301 Moved Permanently
Content-Type: text/plain; charset=utf-8
Date: Sat, 16 May 2015 01:21:08 GMT
Location: /ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/

# curl -IL swagger.luzifer.io
HTTP/1.1 301 Moved Permanently
Content-Type: text/plain; charset=utf-8
Date: Sat, 16 May 2015 01:21:17 GMT
Location: /ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/

HTTP/1.1 301 Moved Permanently
Content-Type: text/plain; charset=utf-8
Date: Sat, 16 May 2015 01:21:17 GMT
Location: /ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/

HTTP/1.1 301 Moved Permanently
Content-Type: text/plain; charset=utf-8
Date: Sat, 16 May 2015 01:21:17 GMT
Location: /ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/

HTTP/1.1 301 Moved Permanently
Content-Type: text/plain; charset=utf-8
Date: Sat, 16 May 2015 01:21:17 GMT
Location: /ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/

HTTP/1.1 301 Moved Permanently
Content-Type: text/plain; charset=utf-8
Date: Sat, 16 May 2015 01:21:17 GMT
Location: /ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/

HTTP/1.1 301 Moved Permanently
Content-Type: text/plain; charset=utf-8
Date: Sat, 16 May 2015 01:21:17 GMT
Location: /ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/

[...]

TODO

  • Test and apply patch from Comments to remove /ipfs/ipfs/... foo
    • it is untested and maybe has side-effects!
  • Find a solution why a dnslink with trailing slash breaks and causes a cascading redirect
    • Why is there even a redirect to the same content the dnslink has?
    • And where does the 301 hide? I don't see it in the sourcecode... 😕
@jbenet
Copy link
Member

jbenet commented May 16, 2015

Latest Docker-Image from jbenet/go-ipfs

You may want ipfs/go-ipfs

@jbenet
Copy link
Member

jbenet commented May 16, 2015

@Luzifer wow, that sucks! any ideas where this could be?

@whyrusleeping
Copy link
Member

@jbenet i can take a look at this in the morning

@Luzifer
Copy link
Member Author

Luzifer commented May 16, 2015

You may want ipfs/go-ipfs

There are no repositories in DockerHub/ipfs. (Should have added I meant DockerHub jbenet/go-ipfs and not the GitHub one… xD)

@Luzifer
Copy link
Member Author

Luzifer commented May 16, 2015

Hmm just discovered the new dnslink feature is already active in that container but sadly that's also not working fine for me…

# dig any swagger.luzifer.io

; <<>> DiG 9.8.3-P1 <<>> any swagger.luzifer.io
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46832
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;swagger.luzifer.io.        IN  ANY

;; ANSWER SECTION:
swagger.luzifer.io. 571 IN  TXT "dnslink=/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/"
swagger.luzifer.io. 571 IN  A   188.40.126.69

;; Query time: 2 msec
;; SERVER: 10.228.0.254#53(10.228.0.254)
;; WHEN: Sat May 16 11:51:09 2015
;; MSG SIZE  rcvd: 126

# curl -i -s swagger.luzifer.io
HTTP/1.1 301 Moved Permanently
Content-Length: 93
Content-Type: text/html; charset=utf-8
Date: Sat, 16 May 2015 09:52:39 GMT
Location: /ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/

<a href="/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/">Moved Permanently</a>.

# curl -IL -s swagger.luzifer.io
HTTP/1.1 301 Moved Permanently
Content-Type: text/plain; charset=utf-8
Date: Sat, 16 May 2015 09:51:23 GMT
Location: /ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/

HTTP/1.1 301 Moved Permanently
Content-Type: text/plain; charset=utf-8
Date: Sat, 16 May 2015 09:51:23 GMT
Location: /ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/

HTTP/1.1 301 Moved Permanently
Content-Type: text/plain; charset=utf-8
Date: Sat, 16 May 2015 09:51:23 GMT
Location: /ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/

HTTP/1.1 301 Moved Permanently
Content-Type: text/plain; charset=utf-8
Date: Sat, 16 May 2015 09:51:23 GMT
Location: /ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/

@Luzifer
Copy link
Member Author

Luzifer commented May 16, 2015

Specifying a file in that folder made it worse:

# dig any swagger.luzifer.io

; <<>> DiG 9.8.3-P1 <<>> any swagger.luzifer.io
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31388
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;swagger.luzifer.io.        IN  ANY

;; ANSWER SECTION:
swagger.luzifer.io. 2   IN  TXT "dnslink=/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/index.html"
swagger.luzifer.io. 542 IN  A   188.40.126.69

;; Query time: 2 msec
;; SERVER: 10.228.0.254#53(10.228.0.254)
;; WHEN: Sat May 16 12:01:37 2015
;; MSG SIZE  rcvd: 136

# curl -i -s swagger.luzifer.io
HTTP/1.1 301 Moved Permanently
Content-Length: 104
Content-Type: text/html; charset=utf-8
Date: Sat, 16 May 2015 10:01:40 GMT
Location: /ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/index.html/

<a href="/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/index.html/">Moved Permanently</a>.

@Luzifer
Copy link
Member Author

Luzifer commented May 16, 2015

Also specifying only the hash did not work:

# dig any swagger.luzifer.io

; <<>> DiG 9.8.3-P1 <<>> any swagger.luzifer.io
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12464
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;swagger.luzifer.io.        IN  ANY

;; ANSWER SECTION:
swagger.luzifer.io. 59  IN  TXT "dnslink=QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA"
swagger.luzifer.io. 599 IN  A   188.40.126.69

;; Query time: 265 msec
;; SERVER: 10.228.0.254#53(10.228.0.254)
;; WHEN: Sat May 16 12:02:52 2015
;; MSG SIZE  rcvd: 119

# curl -i -s swagger.luzifer.io
HTTP/1.1 301 Moved Permanently
Content-Length: 93
Content-Type: text/html; charset=utf-8
Date: Sat, 16 May 2015 10:02:54 GMT
Location: /ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/

<a href="/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/">Moved Permanently</a>.

@Luzifer
Copy link
Member Author

Luzifer commented May 16, 2015

Reproducible with latest source code version, so most likely not a bug in the container:

# curl -i -H 'Host: swagger.luzifer.io' http://localhost:8080/
HTTP/1.1 301 Moved Permanently
Location: /ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/
Date: Sat, 16 May 2015 10:09:46 GMT
Content-Length: 93
Content-Type: text/html; charset=utf-8

<a href="/ipfs/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/">Moved Permanently</a>.

@Luzifer
Copy link
Member Author

Luzifer commented May 16, 2015

DNS resolver works well. (Introduced one more log line to test)

# ./ipfs daemon --debug 2>&1 | grep namesys
12:21:32.829  INFO    namesys: DNSResolver resolving %vswagger.luzifer.io namesys.go:40
12:21:32.879 DEBUG    namesys: Got path from DNS: /ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ namesys.go:40

@Luzifer
Copy link
Member Author

Luzifer commented May 16, 2015

Okay looks like I got the cascading /ipfs/ thing (but there is still the cascading 301 left):

# curl -i -H 'Host: swagger.luzifer.io' http://localhost:8080/
HTTP/1.1 301 Moved Permanently
Location: /ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/
Date: Sat, 16 May 2015 10:28:05 GMT
Content-Length: 88
Content-Type: text/html; charset=utf-8

<a href="/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/">Moved Permanently</a>.
diff --git a/core/corehttp/ipns_hostname.go b/core/corehttp/ipns_hostname.go
index 7361001..a6e8e91 100644
--- a/core/corehttp/ipns_hostname.go
+++ b/core/corehttp/ipns_hostname.go
@@ -20,7 +20,7 @@ func IPNSHostnameOption() ServeOption {

                        host := strings.SplitN(r.Host, ":", 2)[0]
                        if p, err := n.Namesys.Resolve(ctx, host); err == nil {
-                               r.URL.Path = "/ipfs/" + p.String() + r.URL.Path
+                               r.URL.Path = p.String() + r.URL.Path
                        }
                        childMux.ServeHTTP(w, r)
                })

@Luzifer
Copy link
Member Author

Luzifer commented May 16, 2015

Woot. After that change made above it works as soon as I remove the trailing slash from the dnslink:

# dig any swagger.luzifer.io

; <<>> DiG 9.8.3-P1 <<>> any swagger.luzifer.io
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31381
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;swagger.luzifer.io.        IN  ANY

;; ANSWER SECTION:
swagger.luzifer.io. 37  IN  TXT "dnslink=/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA"
swagger.luzifer.io. 577 IN  A   188.40.126.69

;; Query time: 2 msec
;; SERVER: 10.228.0.254#53(10.228.0.254)
;; WHEN: Sat May 16 12:39:52 2015
;; MSG SIZE  rcvd: 125

# curl -s -i -H 'Host: swagger.luzifer.io' http://localhost:8080/ | head -n20
HTTP/1.1 200 OK
Cache-Control: public, max-age=29030400
Etag: QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA
Suborigin: QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA
X-Ipfs-Path: /ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/
Date: Sat, 16 May 2015 10:39:53 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked

<!DOCTYPE html>
<html>
<head>
  <title>Swagger UI</title>

@Luzifer
Copy link
Member Author

Luzifer commented May 16, 2015

(Updated issue with TODO)

@Luzifer
Copy link
Member Author

Luzifer commented May 16, 2015

Specifying a file does work too but not the path with trailing slash:

# dig any swagger.luzifer.io

; <<>> DiG 9.8.3-P1 <<>> any swagger.luzifer.io
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41587
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;swagger.luzifer.io.        IN  ANY

;; ANSWER SECTION:
swagger.luzifer.io. 59  IN  TXT "dnslink=/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/index.html"
swagger.luzifer.io. 599 IN  A   188.40.126.69

;; Query time: 340 msec
;; SERVER: 10.228.0.254#53(10.228.0.254)
;; WHEN: Sat May 16 13:03:40 2015
;; MSG SIZE  rcvd: 136

# curl -s -i -H 'Host: swagger.luzifer.io' http://localhost:8080/ | head -n20
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: public, max-age=29030400
Content-Length: 3921
Content-Type: text/html; charset=utf-8
Etag: index.html
Last-Modified: Thu, 01 Jan 1970 00:00:01 GMT
Suborigin: QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA
X-Ipfs-Path: /ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/index.html/
Date: Sat, 16 May 2015 11:03:43 GMT

<!DOCTYPE html>
<html>
<head>
  <title>Swagger UI</title>

@Luzifer
Copy link
Member Author

Luzifer commented May 16, 2015

Example of remaining redirect cascading:

# dig any swagger.luzifer.io

; <<>> DiG 9.8.3-P1 <<>> any swagger.luzifer.io
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62127
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;swagger.luzifer.io.        IN  ANY

;; ANSWER SECTION:
swagger.luzifer.io. 59  IN  TXT "dnslink=/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/"
swagger.luzifer.io. 599 IN  A   188.40.126.69

;; Query time: 95 msec
;; SERVER: 10.228.0.254#53(10.228.0.254)
;; WHEN: Sat May 16 13:53:43 2015
;; MSG SIZE  rcvd: 126

# curl -s -iL -H 'Host: swagger.luzifer.io' http://localhost:8080/
HTTP/1.1 301 Moved Permanently
Location: /ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/
Date: Sat, 16 May 2015 11:53:57 GMT
Content-Length: 88
Content-Type: text/html; charset=utf-8

HTTP/1.1 301 Moved Permanently
Location: /ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/
Date: Sat, 16 May 2015 11:53:57 GMT
Content-Length: 140
Content-Type: text/html; charset=utf-8

HTTP/1.1 301 Moved Permanently
Location: /ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/
Date: Sat, 16 May 2015 11:53:57 GMT
Content-Length: 192
Content-Type: text/html; charset=utf-8

HTTP/1.1 301 Moved Permanently
Location: /ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/
Date: Sat, 16 May 2015 11:53:57 GMT
Content-Length: 244
Content-Type: text/html; charset=utf-8

HTTP/1.1 301 Moved Permanently
Location: /ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/
Date: Sat, 16 May 2015 11:53:57 GMT
Content-Length: 296
Content-Type: text/html; charset=utf-8

HTTP/1.1 301 Moved Permanently
Location: /ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/
Date: Sat, 16 May 2015 11:53:57 GMT
Content-Length: 348
Content-Type: text/html; charset=utf-8

@Luzifer
Copy link
Member Author

Luzifer commented May 16, 2015

Gotcha!

# curl -si ipfs.hub.luzifer.io/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA//
HTTP/1.1 301 Moved Permanently
Content-Length: 88
Content-Type: text/html; charset=utf-8
Date: Sat, 16 May 2015 13:04:59 GMT
Location: /ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/

<a href="/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/">Moved Permanently</a>.

Fix for both redirect issues:

diff --git a/core/corehttp/ipns_hostname.go b/core/corehttp/ipns_hostname.go
index 7361001..19daefd 100644
--- a/core/corehttp/ipns_hostname.go
+++ b/core/corehttp/ipns_hostname.go
@@ -20,7 +20,7 @@ func IPNSHostnameOption() ServeOption {

                        host := strings.SplitN(r.Host, ":", 2)[0]
                        if p, err := n.Namesys.Resolve(ctx, host); err == nil {
-                               r.URL.Path = "/ipfs/" + p.String() + r.URL.Path
+                               r.URL.Path = strings.TrimRight(p.String(), "/") + r.URL.Path
                        }
                        childMux.ServeHTTP(w, r)
                })

Appending the / from the URL to an IPFS path having a trailing / lead to // which is handled by the mux and removed. Due to the redirect it caused an endless redirect.

@Luzifer
Copy link
Member Author

Luzifer commented May 16, 2015

# dig any swagger.luzifer.io

; <<>> DiG 9.8.3-P1 <<>> any swagger.luzifer.io
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47108
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;swagger.luzifer.io.        IN  ANY

;; ANSWER SECTION:
swagger.luzifer.io. 59  IN  TXT "dnslink=/ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/"
swagger.luzifer.io. 599 IN  A   188.40.126.69

;; Query time: 62 msec
;; SERVER: 10.228.0.254#53(10.228.0.254)
;; WHEN: Sat May 16 15:20:33 2015
;; MSG SIZE  rcvd: 126

# curl -s -iL -H 'Host: swagger.luzifer.io' http://localhost:8080/ | head -n20
HTTP/1.1 200 OK
Cache-Control: public, max-age=29030400
Etag: QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA
Suborigin: QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA
X-Ipfs-Path: /ipfs/QmczrnBpAgnhCo87rtZ8VbLfGU5v8g7cKr7Ef2fKRvYniA/
Date: Sat, 16 May 2015 13:20:37 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked

<!DOCTYPE html>
<html>
<head>
  <title>Swagger UI</title>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants