-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fixing putHandler #1886
fixing putHandler #1886
Conversation
Since #1845 is based on 0.4, I tried my best to get the I fixed overwriting an existing path and 'object add-link' but I'm not sure how in line this are with the old sharness tests and or if we still wont their behavior. |
webError(w, "Could not resolve root object", err, http.StatusBadRequest) | ||
return | ||
} | ||
createfunc := func() *dag.Node { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is uio.NewEmptyDirectory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createfunc := uio.NewEmptyDirectory
Since netstat is not available in the test env, the first test should be commented out. |
if err != nil { | ||
webError(w, "Could not recursively add new node", err, http.StatusInternalServerError) | ||
func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) { | ||
rootPath := path.Path(r.URL.Path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could probably use path.Parse
here
return | ||
var newPath string | ||
if len(rsegs) > 1 { | ||
newPath = filepath.Join(rsegs[2:]...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we dont want to use filepath here, on windows systems this would put forward slashes in the ipfspaths, which i dont think works like we expect it to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ugh, true.. I always manage to ignore that.
just a few comments, then squash some commits so none of them break. (i think some of the earlier ones break) then LGTM |
51cbc49
to
cfc0824
Compare
CR adressed and squashed. |
Please correct me if I have misunderstood the RFC text, but it seems to me like the methods should have the following semantics in this context:
Technically the resulting resource will be added under a new
We will have to decide what to do if the request would overwrite an existing file in
This can not be used to patch
|
You're suggesting PUT should be used only for mutable (ipns) case? |
After a successful This implies mutation. |
Also, I'm generally liking PUT much more than POST when it can be used, but I agree that in the case of ipfs, resources are immutable and PUT doesn't makes sense except at the root when the client already knows the hash of the node it uploads. POST with Content-Disposition should probably be implemented instead. |
w.Header().Set("IPFS-Hash", key.String()) | ||
http.Redirect(w, r, ipfsPathPrefix+key.String()+"/"+strings.Join(components, "/"), http.StatusCreated) | ||
w.Header().Set("IPFS-Hash", newkey.String()) | ||
http.Redirect(w, r, filepath.Join(ipfsPathPrefix, newkey.String(), newPath), http.StatusCreated) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path.
The PR is hard to follow because changes change code quite a bit. i haven't read it all. but if LGTWhyrusleeping, and the tests pass, i'd be ok to merge it. (in the end i want to split out all the gateway stuff into own repo) i think ion covered it very well, all that SGTM. |
@jbenet it's easier to follow if you just look at the new code. Do we want to merge it now and do the change to POST in a follow up PR? The changes will only get bigger because the tests need to change as well. OTOH we would introduce features again that aren't there to stay.. I'd also like to introduce pure go tests for the things @ion1 brought up. I think it's easier to outline and test all those in a table based manner. |
I would be comfortable merging this as its something that is disabled by default. |
I disabled this a long time ago and never refactored it. About time. License: MIT Signed-off-by: Henry <[email protected]>
rebased. I'll start a new branch based on this one for the POST conversion, if we want to do it in this PR I can still push it here. |
} | ||
var newkey key.Key | ||
rnode, err := core.Resolve(i.node.Context(), i.node, rootPath) | ||
switch ev := err.(type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a switch from err casting.
This is cleaner, and should be used across the code.
In current master, where cast is used:
$ grep -rE 'err\.\(' . | grep -v Godeps
./routing/dht/ext_test.go: if merr, ok := err.(u.MultiErr); ok && len(merr) > 0 {
./routing/dht/ext_test.go: if merr, ok := err.(u.MultiErr); ok && len(merr) > 0 {
./routing/dht/ext_test.go: if merr, ok := err.(u.MultiErr); ok && len(merr) > 0 {
./core/corehttp/gateway_handler.go: if _, ok := err.(path.ErrNoLink); ok {
./core/corehttp/gateway_handler.go: if _, ok := err.(path.ErrNoLink); ok {
./core/commands/add.go: if _, ok := err.(*hiddenFileError); ok {
./p2p/net/conn/dial_test.go: if ne, ok := err.(net.Error); ok && ne.Temporary() {
./p2p/net/conn/dial.go: if nerr, ok := err.(net.Error); ok && nerr.Timeout() {
./p2p/net/conn/dial.go: errno, ok := err.(syscall.Errno)
./cmd/ipfs/main.go: switch e := err.(type) {
Unless I'm missing something, to implement POST for composite files on 0.3.x, doesn't it mean the code for |
How is @ion1's |
@@ -273,116 +275,82 @@ func (i *gatewayHandler) postHandler(w http.ResponseWriter, r *http.Request) { | |||
http.Redirect(w, r, ipfsPathPrefix+k.String(), http.StatusCreated) | |||
} | |||
|
|||
func (i *gatewayHandler) putEmptyDirHandler(w http.ResponseWriter, r *http.Request) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happened to this part? do empty dirs still work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup - works by virtue of core.Resolve and friends iirc. There is also a sharness test that checks against the hash.
@cryptix a lot of people want this. eta on addressing CR? |
License: MIT Signed-off-by: Henry <[email protected]>
#1886 (comment) License: MIT Signed-off-by: Henry <[email protected]>
@jbenet done :) |
Thanks @cryptix ! LGTM. I'll merge this for now -- so @victorbjelkholm can use in IPFSBin and @cloutier and @didiercf can use in ipfspics. we can move from |
And ipfs-wiki, which uses |
cc @jamescarlyle o/ |
#1886 (comment) License: MIT Signed-off-by: Henry <[email protected]>
#1886 (comment) License: MIT Signed-off-by: Henry <[email protected]>
#1886 (comment) License: MIT Signed-off-by: Henry <[email protected]>
#1886 (comment) License: MIT Signed-off-by: Henry <[email protected]>
fixing putHandler This commit was moved from ipfs/kubo@f703b2c
trying to finally get a working
putHandler
for the writable http gateway.License: MIT
Signed-off-by: Henry [email protected]