Skip to content

Commit 8a0bc5e

Browse files
Merge pull request ipfs/kubo#3321 from ipfs/feat/resolver-refactor
make path resolver no longer require whole node for construction This commit was moved from ipfs/kubo@17c629d
2 parents 3d100b7 + 6d2ca5e commit 8a0bc5e

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

gateway/core/corehttp/gateway_handler.go

+18-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
dag "github.com/ipfs/go-ipfs/merkledag"
1818
dagutils "github.com/ipfs/go-ipfs/merkledag/utils"
1919
path "github.com/ipfs/go-ipfs/path"
20+
ft "github.com/ipfs/go-ipfs/unixfs"
2021
uio "github.com/ipfs/go-ipfs/unixfs/io"
2122

2223
humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
@@ -153,7 +154,13 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
153154
ipnsHostname = true
154155
}
155156

156-
nd, err := core.Resolve(ctx, i.node, path.Path(urlPath))
157+
p, err := path.ParsePath(urlPath)
158+
if err != nil {
159+
webError(w, "Invalid Path Error", err, http.StatusBadRequest)
160+
return
161+
}
162+
163+
nd, err := core.Resolve(ctx, i.node.Namesys, i.node.Resolver, p)
157164
// If node is in offline mode the error code and message should be different
158165
if err == core.ErrNoNamesys && !i.node.OnlineMode() {
159166
w.WriteHeader(http.StatusServiceUnavailable)
@@ -240,8 +247,14 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
240247
return
241248
}
242249

250+
p, err := path.ParsePath(urlPath + "/index.html")
251+
if err != nil {
252+
internalWebError(w, err)
253+
return
254+
}
255+
243256
// return index page instead.
244-
nd, err := core.Resolve(ctx, i.node, path.Path(urlPath+"/index.html"))
257+
nd, err := core.Resolve(ctx, i.node.Namesys, i.node.Resolver, p)
245258
if err != nil {
246259
internalWebError(w, err)
247260
return
@@ -356,7 +369,7 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
356369

357370
var newnode node.Node
358371
if rsegs[len(rsegs)-1] == "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn" {
359-
newnode = uio.NewEmptyDirectory()
372+
newnode = ft.EmptyDirNode()
360373
} else {
361374
putNode, err := i.newDagFromReader(r.Body)
362375
if err != nil {
@@ -372,7 +385,7 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
372385
}
373386

374387
var newcid *cid.Cid
375-
rnode, err := core.Resolve(ctx, i.node, rootPath)
388+
rnode, err := core.Resolve(ctx, i.node.Namesys, i.node.Resolver, rootPath)
376389
switch ev := err.(type) {
377390
case path.ErrNoLink:
378391
// ev.Node < node where resolve failed
@@ -397,7 +410,7 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
397410
}
398411

399412
e := dagutils.NewDagEditor(pbnd, i.node.DAG)
400-
err = e.InsertNodeAtPath(ctx, newPath, newnode, uio.NewEmptyDirectory)
413+
err = e.InsertNodeAtPath(ctx, newPath, newnode, ft.EmptyDirNode)
401414
if err != nil {
402415
webError(w, "putHandler: InsertNodeAtPath failed", err, http.StatusInternalServerError)
403416
return

0 commit comments

Comments
 (0)