Skip to content
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

disable-last-modified-behaviour-ipns-routes #8074

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,16 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
// set these headers _after_ the error, for we may just not have it
// and don't want the client to cache a 500 response...
// and only if it's /ipfs!
// TODO: break this out when we split /ipfs /ipns routes.
modtime := time.Now()

// ipns routes do not require LastModified header, disable by passing zero date to ServeContent
// (ipfs routes have modtime set in a separate code block below)
modtime := time.Time{}

if f, ok := dr.(files.File); ok {
if strings.HasPrefix(urlPath, ipfsPathPrefix) {
w.Header().Set("Cache-Control", "public, max-age=29030400, immutable")

// set modtime to a really long time ago, since files are immutable and should stay cached
// set modtime for /ipfs/ to a really long time ago, since files are immutable and should stay cached
modtime = time.Unix(1, 0)
}

Expand Down
28 changes: 28 additions & 0 deletions test/sharness/t0110-gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,34 @@ test_expect_success "GET /ipfs/ipns/{peerid} returns redirect to the valid path"
test_should_contain "<link rel=\"canonical\" href=\"/ipns/${PEERID}?query=to-remember\" />" response_with_ipfs_ipns_ns
'

# Headers related to caching
# Cache-Control: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
# Last-Modified: https://github.com/ipfs/go-ipfs/issues/7968
# Etag: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag

# /ipfs/*
test_expect_success "GET for /ipfs/ should include the ancient Last-Modified header" "
curl -svX GET 'http://127.0.0.1:$port/ipfs/$HASH' > curl_out 2>&1 &&
grep -i 'Last-Modified: Thu, 01 Jan 1970 00:00:01 GMT' curl_out
"
test_expect_success "GET for /ipfs/ should include maxed out Cache-Control header" "
grep -i 'Cache-Control: public, max-age=29030400, immutable' curl_out
"
test_expect_success "GET for /ipfs/ should include Etag header set to the CID" "
grep -i 'Etag: \"${HASH}\"' curl_out
"

# /ipns/*
test_expect_success "GET for /ipns/ should not include Last-Modified header" "
curl -svX GET 'http://127.0.0.1:$port/ipns/$PEERID' > curl_out 2>&1 &&
test_must_fail grep -i 'Last-Modified' curl_out
"
test_expect_success "GET for /ipns/ should include Etag header set to the current CID" "
grep -i 'Etag: \"${HASH}\"' curl_out
"
# TODO: set Cache-Control for /ipns/ based on the TTL of IPNS or DNSLink record


test_expect_success "GET invalid IPFS path errors" '
test_must_fail curl -sf "http://127.0.0.1:$port/ipfs/12345"
'
Expand Down