Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cb56ec1

Browse files
committedNov 19, 2015
add closenotify and large timeout to gateway
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent 5f8cfc9 commit cb56ec1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed
 

‎core/corehttp/gateway_handler.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,20 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
8686
}
8787

8888
func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request) {
89-
ctx, cancel := context.WithCancel(i.node.Context())
89+
ctx, cancel := context.WithTimeout(i.node.Context(), time.Hour)
90+
// the hour is a hard fallback, we don't expect it to happen, but just in case
9091
defer cancel()
9192

93+
if cn, ok := w.(http.CloseNotifier); ok {
94+
go func() {
95+
select {
96+
case <-cn.CloseNotify():
97+
case <-ctx.Done():
98+
}
99+
cancel()
100+
}()
101+
}
102+
92103
urlPath := r.URL.Path
93104

94105
// IPNSHostnameOption might have constructed an IPNS path using the Host header.

0 commit comments

Comments
 (0)
Please sign in to comment.