Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
Remove CloseNotifier
Browse files Browse the repository at this point in the history
The CloseNotifier is in conflict with the Hijacker interface (they
cannot be used at the same time). The context will not be cancelled when
the close channel from CloseNotifier is called. This is because the behavior
is not well understood. We can introduce it later if it poses a real problem.

refs #291
  • Loading branch information
cheungpat authored and rickmak committed Feb 15, 2017
1 parent 16f84de commit b1a2c5e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 23 deletions.
16 changes: 0 additions & 16 deletions pkg/server/router/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func (r *commonRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
preprocessors []Processor
payload *Payload
timedOut bool
closed bool
)

version := strings.TrimPrefix(skyversion.Version(), "v")
Expand Down Expand Up @@ -77,11 +76,6 @@ func (r *commonRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
httpStatus = defaultStatusCode(resp.Err)
}

if closed {
// There is no point writing to a closed connection.
return
}

writer.WriteHeader(httpStatus)
if err := writeEntity(writer, resp); err != nil {
panic(err)
Expand Down Expand Up @@ -118,9 +112,6 @@ func (r *commonRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
select {
case <-payload.Context.Done():
// request conext cancelled or response generated
case <-getCloseChan(w):
// connection closed
closed = true
case <-getTimeoutChan(r.ResponseTimeout):
// timeout exceeded
timedOut = true
Expand Down Expand Up @@ -160,13 +151,6 @@ func writeEntity(w http.ResponseWriter, i interface{}) error {
return json.NewEncoder(w).Encode(i)
}

func getCloseChan(w http.ResponseWriter) <-chan bool {
if closeNotifier, ok := w.(http.CloseNotifier); ok {
return closeNotifier.CloseNotify()
}
return make(chan bool)
}

func getTimeoutChan(timeout time.Duration) <-chan time.Time {
if timeout.Seconds() > 0 {
return time.After(timeout)
Expand Down
7 changes: 0 additions & 7 deletions pkg/server/router/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ func (l *responseLogger) Hijack() (c net.Conn, w *bufio.ReadWriter, e error) {
return hijacker.Hijack()
}

func (l *responseLogger) CloseNotify() <-chan bool {
if notifier, ok := l.w.(http.CloseNotifier); ok {
return notifier.CloseNotify()
}
return make(chan bool)
}

type LoggingMiddleware struct {
Skips []string
MimeConcern []string
Expand Down

0 comments on commit b1a2c5e

Please sign in to comment.