提交 5d27d74c 作者: James Stanley 提交者: Steven Allen

Give a 400 for PUT to a name ending in a /

License: MIT
Signed-off-by: 's avatarJames Stanley <james@incoherency.co.uk>
上级 56c27ee0
...@@ -398,6 +398,11 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) { ...@@ -398,6 +398,11 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
if rootPath[len(rootPath)-1] == '/' {
webError(w, "putHandler: can't PUT a directory", err, http.StatusBadRequest)
return
}
rsegs := rootPath.Segments() rsegs := rootPath.Segments()
if rsegs[0] == ipnsPathPrefix { if rsegs[0] == ipnsPathPrefix {
webError(w, "putHandler: updating named entries not supported", errors.New("WritableGateway: ipns put not supported"), http.StatusBadRequest) webError(w, "putHandler: updating named entries not supported", errors.New("WritableGateway: ipns put not supported"), http.StatusBadRequest)
...@@ -427,39 +432,33 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) { ...@@ -427,39 +432,33 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
var newcid *cid.Cid rnode, err := i.node.DAG.Get(ctx, c)
if newPath == "" { if err != nil {
// not inserting anything: directory tree is unchanged webError(w, "putHandler: Could not create DAG from request", err, http.StatusInternalServerError)
newcid = c return
} else { }
rnode, err := i.node.DAG.Get(ctx, c)
if err != nil {
webError(w, "putHandler: Could not create DAG from request", err, http.StatusInternalServerError)
return
}
pbnd, ok := rnode.(*dag.ProtoNode)
if !ok {
webError(w, "Cannot read non protobuf nodes through gateway", dag.ErrNotProtobuf, http.StatusBadRequest)
return
}
e := dagutils.NewDagEditor(pbnd, i.node.DAG) pbnd, ok := rnode.(*dag.ProtoNode)
err = e.InsertNodeAtPath(ctx, newPath, newnode, ft.EmptyDirNode) if !ok {
if err != nil { webError(w, "Cannot read non protobuf nodes through gateway", dag.ErrNotProtobuf, http.StatusBadRequest)
webError(w, "putHandler: InsertNodeAtPath failed", err, http.StatusInternalServerError) return
return }
}
nnode, err := e.Finalize(ctx, i.node.DAG) e := dagutils.NewDagEditor(pbnd, i.node.DAG)
if err != nil { err = e.InsertNodeAtPath(ctx, newPath, newnode, ft.EmptyDirNode)
webError(w, "putHandler: could not get node", err, http.StatusInternalServerError) if err != nil {
return webError(w, "putHandler: InsertNodeAtPath failed", err, http.StatusInternalServerError)
} return
}
newcid = nnode.Cid() nnode, err := e.Finalize(ctx, i.node.DAG)
if err != nil {
webError(w, "putHandler: could not get node", err, http.StatusInternalServerError)
return
} }
newcid := nnode.Cid()
i.addUserHeaders(w) // ok, _now_ write user's headers. i.addUserHeaders(w) // ok, _now_ write user's headers.
w.Header().Set("IPFS-Hash", newcid.String()) w.Header().Set("IPFS-Hash", newcid.String())
http.Redirect(w, r, gopath.Join(ipfsPathPrefix, newcid.String(), newPath), http.StatusCreated) http.Redirect(w, r, gopath.Join(ipfsPathPrefix, newcid.String(), newPath), http.StatusCreated)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论