Skip to content

Commit 6ab98aa

Browse files
committedNov 30, 2022
feat: cleanup and leverage caching
1 parent 4e627e4 commit 6ab98aa

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed
 

‎core/corehttp/gateway_handler.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,8 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
435435
i.serveTAR(r.Context(), w, r, resolvedPath, contentPath, begin, logger)
436436
return
437437
case "application/vnd.ipfs.ipns-record":
438-
// TODO: i.handlePathResolution has been executed here, but we don't really need it. Should we check
439-
// this beforehand?
440438
logger.Debugw("serving ipns record", "path", contentPath)
441-
i.serveIpnsRecord(r.Context(), w, r, contentPath, begin, logger)
439+
i.serveIpnsRecord(r.Context(), w, r, resolvedPath, contentPath, begin, logger)
442440
return
443441
default: // catch-all for unsuported application/vnd.*
444442
err := fmt.Errorf("unsupported format %q", responseFormat)

‎core/corehttp/gateway_handler_ipns_record.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"go.uber.org/zap"
1414
)
1515

16-
func (i *gatewayHandler) serveIpnsRecord(ctx context.Context, w http.ResponseWriter, r *http.Request, contentPath ipath.Path, begin time.Time, logger *zap.SugaredLogger) {
16+
func (i *gatewayHandler) serveIpnsRecord(ctx context.Context, w http.ResponseWriter, r *http.Request, resolvedPath ipath.Resolved, contentPath ipath.Path, begin time.Time, logger *zap.SugaredLogger) {
1717
if contentPath.Namespace() != "ipns" {
1818
err := fmt.Errorf("%s is not an IPNS link", contentPath.String())
1919
webError(w, err.Error(), err, http.StatusBadRequest)
@@ -34,6 +34,11 @@ func (i *gatewayHandler) serveIpnsRecord(ctx context.Context, w http.ResponseWri
3434
return
3535
}
3636

37+
// Set cache control headers. See the linked issue for improvements on
38+
// IPNS caching based on keys' TTL.
39+
// https://github.com/ipfs/kubo/issues/1818#issuecomment-1015849462
40+
_ = addCacheControlHeaders(w, r, contentPath, resolvedPath.Cid())
41+
3742
// Set Content-Disposition
3843
var name string
3944
if urlFilename := r.URL.Query().Get("filename"); urlFilename != "" {

0 commit comments

Comments
 (0)