diff --git a/gateway/core/corehttp/gateway_test.go b/gateway/core/corehttp/gateway_test.go index e1e026cd1..900020cba 100644 --- a/gateway/core/corehttp/gateway_test.go +++ b/gateway/core/corehttp/gateway_test.go @@ -40,7 +40,10 @@ func (m mockNamesys) Resolve(ctx context.Context, name string, opts ...nsopts.Re if depth == nsopts.UnlimitedDepth { depth = math.MaxUint64 } - for depth > 0 && strings.HasPrefix(name, "/ipns/") { + for strings.HasPrefix(name, "/ipns/") { + if depth <= 0 { + return value, namesys.ErrResolveRecursion + } depth-- var ok bool diff --git a/gateway/core/corehttp/ipns_hostname.go b/gateway/core/corehttp/ipns_hostname.go index 7bce62ad3..346acc6c3 100644 --- a/gateway/core/corehttp/ipns_hostname.go +++ b/gateway/core/corehttp/ipns_hostname.go @@ -7,6 +7,7 @@ import ( "strings" core "github.com/ipfs/go-ipfs/core" + namesys "github.com/ipfs/go-ipfs/namesys" nsopts "github.com/ipfs/go-ipfs/namesys/opts" isd "gx/ipfs/QmZmmuAXgX73UQmX1jRKjTGmjzq24Jinqkq8vzkBtno4uX/go-is-domain" @@ -25,7 +26,8 @@ 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, nsopts.Depth(1)); err == nil { + _, err := n.Namesys.Resolve(ctx, name, nsopts.Depth(1)) + if err == nil || err == namesys.ErrResolveRecursion { r.Header.Set("X-Ipns-Original-Path", r.URL.Path) r.URL.Path = name + r.URL.Path }