Skip to content

Commit

Permalink
Merge pull request #5782 from ipfs/feat/http-context
Browse files Browse the repository at this point in the history
Switch to using request.Context()
  • Loading branch information
Stebalien authored Nov 19, 2018
2 parents 31099e8 + da4674f commit ebc7cdc
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,11 @@ func (i *gatewayHandler) newDagFromReader(r io.Reader) (ipld.Node, error) {
chunker.DefaultSplitter(r))
}

// TODO(btc): break this apart into separate handlers using a more expressive muxer
func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(i.node.Context(), time.Hour)
// the hour is a hard fallback, we don't expect it to happen, but just in case
ctx, cancel := context.WithTimeout(r.Context(), time.Hour)
defer cancel()

if cn, ok := w.(http.CloseNotifier); ok {
clientGone := cn.CloseNotify()
go func() {
select {
case <-clientGone:
case <-ctx.Done():
}
cancel()
}()
}

defer func() {
if r := recover(); r != nil {
log.Error("A panic occurred in the gateway handler!")
Expand Down

0 comments on commit ebc7cdc

Please sign in to comment.