Browse Source

Remove graceful.Middleware from the public API

It was exposed mostly for documentation of a Go 1.2 polyfill, and really
doesn't feel like it should be exposed long-term, since it hasn't done
anything in frightfully long.

This is a breaking change for advanced users of package graceful, for
which there is unfortunately no easy workaround (at least for Go 1.2
users, which are the ~only ones affected).
Carl Jackson 11 years ago
parent
commit
b9d27b2f34
4 changed files with 6 additions and 41 deletions
  1. +3
    -24
      graceful/middleware.go
  2. +0
    -12
      graceful/middleware13.go
  3. +1
    -1
      graceful/serve.go
  4. +2
    -4
      graceful/serve13.go

+ 3
- 24
graceful/middleware.go View File

@ -12,30 +12,9 @@ import (
"github.com/zenazn/goji/graceful/listener"
)
/*
Middleware adds graceful shutdown capabilities to the given handler. When a
graceful shutdown is in progress, this middleware intercepts responses to add a
"Connection: close" header to politely inform the client that we are about to go
away.
This package creates a shim http.ResponseWriter that it passes to subsequent
handlers. Unfortunately, there's a great many optional interfaces that this
http.ResponseWriter might implement (e.g., http.CloseNotifier, http.Flusher, and
http.Hijacker), and in order to perfectly proxy all of these options we'd be
left with some kind of awful powerset of ResponseWriters, and that's not even
counting all the other custom interfaces you might be expecting. Instead of
doing that, we have implemented two kinds of proxies: one that contains no
additional methods (i.e., exactly corresponding to the http.ResponseWriter
interface), and one that supports all three of http.CloseNotifier, http.Flusher,
and http.Hijacker. If you find that this is not enough, the original
http.ResponseWriter can be retrieved by calling Unwrap() on the proxy object.
This middleware is automatically applied to every http.Handler passed to this
package, and most users will not need to call this function directly. It is
exported primarily for documentation purposes and in the off chance that someone
really wants more control over their http.Server than we currently provide.
*/
func Middleware(h http.Handler) http.Handler {
// Middleware provides functionality similar to net/http.Server's
// SetKeepAlivesEnabled in Go 1.3, but in Go 1.2.
func middleware(h http.Handler) http.Handler {
if h == nil {
return nil
}


+ 0
- 12
graceful/middleware13.go View File

@ -1,12 +0,0 @@
// +build go1.3
package graceful
import "net/http"
// Middleware is a stub that does nothing. When used with versions of Go before
// Go 1.3, it provides functionality similar to net/http.Server's
// SetKeepAlivesEnabled.
func Middleware(h http.Handler) http.Handler {
return h
}

+ 1
- 1
graceful/serve.go View File

@ -22,7 +22,7 @@ func (srv *Server) Serve(l net.Listener) error {
if shadow.ReadTimeout == 0 {
shadow.ReadTimeout = forever
}
shadow.Handler = Middleware(shadow.Handler)
shadow.Handler = middleware(shadow.Handler)
wrap := listener.Wrap(l, listener.Deadline)
appendListener(wrap)


+ 2
- 4
graceful/serve13.go View File

@ -47,13 +47,11 @@ func (c connState) Wrap(nc net.Conn, s http.ConnState) {
switch s {
case http.StateIdle:
if err := listener.MarkIdle(nc); err != nil {
log.Printf("error marking conn as idle: %v",
err)
log.Printf("error marking conn as idle: %v", err)
}
case http.StateHijacked:
if err := listener.Disown(nc); err != nil {
log.Printf("error disowning hijacked conn: %v",
err)
log.Printf("error disowning hijacked conn: %v", err)
}
}
if c != nil {


Loading…
Cancel
Save