Skip to content
Myr

Set a 2-second timeout for POST requests

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Close #3685

authored by Junegunn Choi · committed by Junegunn Choi · parent 5e47ab9 · Browse files · 1 file+7 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+7 added−2 removed

  • other:+7 added−2 removed

1 file+7 added−2 removed

modified:src/server.go+7 added-2 removed
30 unmodified lines
31 httpBadRequest = "HTTP/1.1 400 Bad Request" + crlf32 httpUnauthorized = "HTTP/1.1 401 Unauthorized" + crlf33 httpUnavailable = "HTTP/1.1 503 Service Unavailable" + crlf34 httpReadTimeout = 10 * time.Second35 channelTimeout = 2 * time.Second36 jsonContentType = "Content-Type: application/json" + crlf37 maxContentLength = 1024 * 102438)39
130 unmodified lines
170 server.actionChannel <- []*action{{t: actResponse, a: getMatch[1]}}171 select {172 case response := <-server.responseChannel:173 return good(response)173 case <-time.After(2 * time.Second):174 case <-time.After(channelTimeout):175 go func() {176 // Drain the channel177 <-server.responseChannel178 }()
48 unmodified lines
227 if len(actions) == 0 {228 return bad("no action specified")229 }230230 server.actionChannel <- actions231 select {232 case server.actionChannel <- actions:233 case <-time.After(channelTimeout):234 return httpUnavailable + crlf235 }236 return httpOk + crlf237}238239func parseGetParams(query string) getParams {
18 unmodified lines