Skip to content

Commit

Permalink
fix: return 400 if not unixfs
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Oct 13, 2022
1 parent b752021 commit d2ee1d1
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions core/corehttp/gateway_handler_tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ func (i *gatewayHandler) serveTAR(ctx context.Context, w http.ResponseWriter, r
ctx, cancel := context.WithCancel(ctx)
defer cancel()

// Get Unixfs file
file, err := i.api.Unixfs().Get(ctx, resolvedPath)
if err != nil {
webError(w, "ipfs cat "+html.EscapeString(contentPath.String()), err, http.StatusBadRequest)
return
}
defer file.Close()

// Set Cache-Control and read optional Last-Modified time
modtime := addCacheControlHeaders(w, r, contentPath, resolvedPath.Cid())

Expand All @@ -41,14 +49,6 @@ func (i *gatewayHandler) serveTAR(ctx context.Context, w http.ResponseWriter, r
}
setContentDispositionHeader(w, name, "attachment")

// Get Unixfs file
file, err := i.api.Unixfs().Get(ctx, resolvedPath)
if err != nil {
webError(w, "ipfs cat "+html.EscapeString(contentPath.String()), err, http.StatusNotFound)
return
}
defer file.Close()

// Construct the TAR writer
tarw, err := files.NewTarWriter(w)
if err != nil {
Expand Down

0 comments on commit d2ee1d1

Please sign in to comment.