mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 03:47:45 +08:00
Merge pull request #5782 from ipfs/feat/http-context
Switch to using request.Context()
This commit is contained in:
commit
ebc7cdceb5
@ -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!")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user