Skip to content

Commit

Permalink
refactor: add abortConn in tar handler
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Nov 10, 2022
1 parent 32c1f9b commit 94f0399
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions core/corehttp/gateway_handler_tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ func (i *gatewayHandler) serveTAR(ctx context.Context, w http.ResponseWriter, r

// The TAR has a top-level directory (or file) named by the CID.
if err := tarw.WriteFile(file, rootCid.String()); err != nil {
w.Header().Set("X-Stream-Error", err.Error())
// Trailer headers do not work in web browsers
// (see https://github.com/mdn/browser-compat-data/issues/14703)
// and we have limited options around error handling in browser contexts.
// To improve UX/DX, we finish response stream with error message, allowing client to
// (1) detect error by having corrupted TAR
// (2) be able to reason what went wrong by instecting the tail of TAR stream
_, _ = w.Write([]byte(err.Error()))
return
abortConn(w)
}
}

0 comments on commit 94f0399

Please sign in to comment.