Switch to using request.Context()
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Nov 18, 2018 at 16:11 UTC
da4674f0b9b329c716a51f4fd0f505844c9ca0fd
1 file changed
+1
-13
core/corehttp/gateway_handler.go
+1
-13
@@ -64,23 +64,11 @@ func (i *gatewayHandler) newDagFromReader(r io.Reader) (ipld.Node, error) {
64
chunker.DefaultSplitter(r))
65
}
66
67
-// TODO(btc): break this apart into separate handlers using a more expressive muxer
67
func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
69
- ctx, cancel := context.WithTimeout(i.node.Context(), time.Hour)
68
// the hour is a hard fallback, we don't expect it to happen, but just in case
69
+ ctx, cancel := context.WithTimeout(r.Context(), time.Hour)
70
defer cancel()
71
73
- if cn, ok := w.(http.CloseNotifier); ok {
74
- clientGone := cn.CloseNotify()
75
- go func() {
76
- select {
77
- case <-clientGone:
78
- case <-ctx.Done():
79
- }
80
- cancel()
81
- }()
82
- }
83
-
72
defer func() {
73
if r := recover(); r != nil {
74
log.Error("A panic occurred in the gateway handler!")