Skip to content

Commit

Permalink
feat: cleanup and leverage caching
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Nov 30, 2022
1 parent d17c184 commit 990586f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 1 addition & 3 deletions core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,8 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
i.serveTAR(r.Context(), w, r, resolvedPath, contentPath, begin, logger)
return
case "application/vnd.ipfs.ipns-record":
// TODO: i.handlePathResolution has been executed here, but we don't really need it. Should we check
// this beforehand?
logger.Debugw("serving ipns record", "path", contentPath)
i.serveIpnsRecord(r.Context(), w, r, contentPath, begin, logger)
i.serveIpnsRecord(r.Context(), w, r, resolvedPath, contentPath, begin, logger)
return
default: // catch-all for unsuported application/vnd.*
err := fmt.Errorf("unsupported format %q", responseFormat)
Expand Down
7 changes: 6 additions & 1 deletion core/corehttp/gateway_handler_ipns_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"go.uber.org/zap"
)

func (i *gatewayHandler) serveIpnsRecord(ctx context.Context, w http.ResponseWriter, r *http.Request, contentPath ipath.Path, begin time.Time, logger *zap.SugaredLogger) {
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) {
if contentPath.Namespace() != "ipns" {
err := fmt.Errorf("%s is not an IPNS link", contentPath.String())
webError(w, err.Error(), err, http.StatusBadRequest)
Expand All @@ -34,6 +34,11 @@ func (i *gatewayHandler) serveIpnsRecord(ctx context.Context, w http.ResponseWri
return
}

// Set cache control headers. See the linked issue for improvements on
// IPNS caching based on keys' TTL.
// https://github.com/ipfs/kubo/issues/1818#issuecomment-1015849462
_ = addCacheControlHeaders(w, r, contentPath, resolvedPath.Cid())

// Set Content-Disposition
var name string
if urlFilename := r.URL.Query().Get("filename"); urlFilename != "" {
Expand Down

0 comments on commit 990586f

Please sign in to comment.