Skip to content

Commit

Permalink
gateway add: add option for pin
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: rht <rhtbot@gmail.com>
  • Loading branch information
rht committed Nov 12, 2015
1 parent 02f9a5b commit 2c629a3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@ func (i *gatewayHandler) postHandler(w http.ResponseWriter, r *http.Request) {
return
}

doPin := r.FormValue("pin")
if doPin == "" || doPin == "true" {
if err := fileAdder.PinRoot(); err != nil {
internalWebError(w, err)
return
}
}

i.addUserHeaders(w) // ok, _now_ write user's headers.
w.Header().Set("IPFS-Hash", k.String())
http.Redirect(w, r, ipfsPathPrefix+k.String(), http.StatusCreated)
Expand Down
23 changes: 23 additions & 0 deletions test/sharness/t0111-gateway-writeable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ test_expect_success "We can HTTP GET file just created" '
test_cmp infile outfile
'

test_expect_success "File is pinned (unpin file should work)" '
ipfs pin rm -r $HASH
'

test_expect_success "HTTP POST file with unpin flag gives Hash" '
echo "$RANDOM" >infile &&
URL="http://localhost:$port/ipfs/?pin=false" &&
curl -svX POST --data-binary @infile "$URL" 2>curl_post.out &&
grep "HTTP/1.1 201 Created" curl_post.out &&
LOCATION=$(grep Location curl_post.out) &&
HASH=$(echo $LOCATION | cut -d":" -f2- |tr -d " \n\r")
'

test_expect_success "We can HTTP GET file just created" '
URL="http://localhost:${port}${HASH}" &&
curl -so outfile "$URL" &&
test_cmp infile outfile
'

test_expect_success "File is not pinned (unpin file should fail)" '
test_must_fail ipfs pin rm -r $HASH
'

test_expect_success "HTTP PUT empty directory" '
URL="http://localhost:$port/ipfs/$HASH_EMPTY_DIR/" &&
echo "PUT $URL" &&
Expand Down

0 comments on commit 2c629a3

Please sign in to comment.