only resolve dnslinks once in the gateway

If the domain has a DNS-Link, we want to use it even if it points to, e.g., an
IPNS address that doesn't resolve.

fixes #4973

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
This commit is contained in:
Steven Allen 2018-04-25 00:00:37 -07:00
parent e235d02188
commit 31bb974bb1

View File

@ -6,7 +6,8 @@ import (
"net/http"
"strings"
"github.com/ipfs/go-ipfs/core"
core "github.com/ipfs/go-ipfs/core"
nsopts "github.com/ipfs/go-ipfs/namesys/opts"
isd "gx/ipfs/QmZmmuAXgX73UQmX1jRKjTGmjzq24Jinqkq8vzkBtno4uX/go-is-domain"
)
@ -24,7 +25,7 @@ func IPNSHostnameOption() ServeOption {
host := strings.SplitN(r.Host, ":", 2)[0]
if len(host) > 0 && isd.IsDomain(host) {
name := "/ipns/" + host
if _, err := n.Namesys.Resolve(ctx, name); err == nil {
if _, err := n.Namesys.Resolve(ctx, name, nsopts.Depth(1)); err == nil {
r.Header["X-Ipns-Original-Path"] = []string{r.URL.Path}
r.URL.Path = name + r.URL.Path
}