Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
c31e4f72
Commit
c31e4f72
authored
Sep 20, 2016
by
Lars Gierth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gateway: move context/close-notify wiring
License: MIT Signed-off-by:
Lars Gierth
<
larsg@systemli.org
>
parent
036ca3a7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
16 deletions
+17
-16
core/corehttp/gateway_handler.go
core/corehttp/gateway_handler.go
+17
-16
No files found.
core/corehttp/gateway_handler.go
View file @
c31e4f72
...
...
@@ -60,6 +60,21 @@ func (i *gatewayHandler) newDagFromReader(r io.Reader) (node.Node, error) {
// 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
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!"
)
...
...
@@ -83,7 +98,7 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
if
r
.
Method
==
"GET"
||
r
.
Method
==
"HEAD"
{
i
.
getOrHeadHandler
(
w
,
r
)
i
.
getOrHeadHandler
(
ctx
,
w
,
r
)
return
}
...
...
@@ -113,21 +128,7 @@ func (i *gatewayHandler) optionsHandler(w http.ResponseWriter, r *http.Request)
i
.
addUserHeaders
(
w
)
// return all custom headers (including CORS ones, if set)
}
func
(
i
*
gatewayHandler
)
getOrHeadHandler
(
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
defer
cancel
()
if
cn
,
ok
:=
w
.
(
http
.
CloseNotifier
);
ok
{
clientGone
:=
cn
.
CloseNotify
()
go
func
()
{
select
{
case
<-
clientGone
:
case
<-
ctx
.
Done
()
:
}
cancel
()
}()
}
func
(
i
*
gatewayHandler
)
getOrHeadHandler
(
ctx
context
.
Context
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
urlPath
:=
r
.
URL
.
Path
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment