Skip to content

Commit

Permalink
remove closenotifier
Browse files Browse the repository at this point in the history
Signed-off-by: David Wu <david.wu@docker.com>
  • Loading branch information
David Wu committed Sep 11, 2018
1 parent 166874a commit bd41413
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 66 deletions.
30 changes: 0 additions & 30 deletions context/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,6 @@ func GetRequestID(ctx context.Context) string {
// WithResponseWriter returns a new context and response writer that makes
// interesting response statistics available within the context.
func WithResponseWriter(ctx context.Context, w http.ResponseWriter) (context.Context, http.ResponseWriter) {
if closeNotifier, ok := w.(http.CloseNotifier); ok {
irwCN := &instrumentedResponseWriterCN{
instrumentedResponseWriter: instrumentedResponseWriter{
ResponseWriter: w,
Context: ctx,
},
CloseNotifier: closeNotifier,
}

return irwCN, irwCN
}

irw := instrumentedResponseWriter{
ResponseWriter: w,
Context: ctx,
Expand Down Expand Up @@ -270,14 +258,6 @@ func (ctx *muxVarsContext) Value(key interface{}) interface{} {
return ctx.Context.Value(key)
}

// instrumentedResponseWriterCN provides response writer information in a
// context. It implements http.CloseNotifier so that users can detect
// early disconnects.
type instrumentedResponseWriterCN struct {
instrumentedResponseWriter
http.CloseNotifier
}

// instrumentedResponseWriter provides response writer information in a
// context. This variant is only used in the case where CloseNotifier is not
// implemented by the parent ResponseWriter.
Expand Down Expand Up @@ -355,13 +335,3 @@ func (irw *instrumentedResponseWriter) Value(key interface{}) interface{} {
fallback:
return irw.Context.Value(key)
}

func (irw *instrumentedResponseWriterCN) Value(key interface{}) interface{} {
if keyStr, ok := key.(string); ok {
if keyStr == "http.response" {
return irw
}
}

return irw.instrumentedResponseWriter.Value(key)
}
29 changes: 0 additions & 29 deletions registry/handlers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2529,35 +2529,6 @@ func TestRegistryAsCacheMutationAPIs(t *testing.T) {

}

// TestCheckContextNotifier makes sure the API endpoints get a ResponseWriter
// that implements http.ContextNotifier.
func TestCheckContextNotifier(t *testing.T) {
env := newTestEnv(t, false)
defer env.Shutdown()

// Register a new endpoint for testing
env.app.router.Handle("/unittest/{name}/", env.app.dispatcher(func(ctx *Context, r *http.Request) http.Handler {
return handlers.MethodHandler{
"GET": http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if _, ok := w.(http.CloseNotifier); !ok {
t.Fatal("could not cast ResponseWriter to CloseNotifier")
}
w.WriteHeader(200)
}),
}
}))

resp, err := http.Get(env.server.URL + "/unittest/reponame/")
if err != nil {
t.Fatalf("unexpected error issuing request: %v", err)
}
defer resp.Body.Close()

if resp.StatusCode != 200 {
t.Fatalf("wrong status code - expected 200, got %d", resp.StatusCode)
}
}

func TestProxyManifestGetByTag(t *testing.T) {
truthConfig := configuration.Configuration{
Storage: configuration.Storage{
Expand Down
8 changes: 1 addition & 7 deletions registry/handlers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ func closeResources(handler http.Handler, closers ...io.Closer) http.Handler {
// The copy will be limited to `limit` bytes, if limit is greater than zero.
func copyFullPayload(ctx context.Context, responseWriter http.ResponseWriter, r *http.Request, destWriter io.Writer, limit int64, action string) error {
// Get a channel that tells us if the client disconnects
var clientClosed <-chan bool
if notifier, ok := responseWriter.(http.CloseNotifier); ok {
clientClosed = notifier.CloseNotify()
} else {
dcontext.GetLogger(ctx).Warnf("the ResponseWriter does not implement CloseNotifier (type: %T)", responseWriter)
}

clientClosed := r.Context().Done()
var body = r.Body
if limit > 0 {
body = http.MaxBytesReader(responseWriter, body, limit)
Expand Down

0 comments on commit bd41413

Please sign in to comment.