Skip to content

Commit

Permalink
fix(gw): send 200 for empty files
Browse files Browse the repository at this point in the history
Fixes ipfs#9238
  • Loading branch information
Jorropo committed Aug 31, 2022
1 parent 426cb84 commit 1ff8677
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/corehttp/gateway_handler_unixfs_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ func (i *gatewayHandler) serveFile(ctx context.Context, w http.ResponseWriter, r
return
}

if size == 0 {
// We override null files to 200 to avoid issues with fragment caching reverse proxies.
// Also whatever you are asking for, it's cheaper to just give you the complete file (nothing).
w.WriteHeader(http.StatusOK)
return
}

// Lazy seeker enables efficient range-requests and HTTP HEAD responses
content := &lazySeeker{
size: size,
Expand Down
7 changes: 7 additions & 0 deletions test/sharness/t0110-gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ test_expect_success "GET IPFS inlined zero-length data object returns ok code (2
test_should_contain "Content-Length: 0" empty_ok_response
'

# https://github.com/ipfs/kubo/issues/9238
test_expect_success "GET IPFS inlined zero-length data object with byte range starting at 0 returns ok code (200)" '
curl -sD - "http://127.0.0.1:$port/ipfs/bafkqaaa" -H "Range: bytes=0-1048575" > empty_ok_response &&
test_should_contain "HTTP/1.1 200 OK" empty_ok_response &&
test_should_contain "Content-Length: 0" empty_ok_response
'

test_expect_success "GET /ipfs/ipfs/{cid} returns redirect to the valid path" '
curl -sD - "http://127.0.0.1:$port/ipfs/ipfs/bafkqaaa?query=to-remember" > response_with_double_ipfs_ns &&
test_should_contain "<meta http-equiv=\"refresh\" content=\"10;url=/ipfs/bafkqaaa?query=to-remember\" />" response_with_double_ipfs_ns &&
Expand Down

0 comments on commit 1ff8677

Please sign in to comment.