forked from TrueCloudLab/distribution
remove closenotifier
Signed-off-by: David Wu <david.wu@docker.com>
This commit is contained in:
parent
166874ade9
commit
bd41413d57
3 changed files with 1 additions and 66 deletions
|
@ -104,18 +104,6 @@ func GetRequestID(ctx context.Context) string {
|
||||||
// WithResponseWriter returns a new context and response writer that makes
|
// WithResponseWriter returns a new context and response writer that makes
|
||||||
// interesting response statistics available within the context.
|
// interesting response statistics available within the context.
|
||||||
func WithResponseWriter(ctx context.Context, w http.ResponseWriter) (context.Context, http.ResponseWriter) {
|
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{
|
irw := instrumentedResponseWriter{
|
||||||
ResponseWriter: w,
|
ResponseWriter: w,
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
|
@ -270,14 +258,6 @@ func (ctx *muxVarsContext) Value(key interface{}) interface{} {
|
||||||
return ctx.Context.Value(key)
|
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
|
// instrumentedResponseWriter provides response writer information in a
|
||||||
// context. This variant is only used in the case where CloseNotifier is not
|
// context. This variant is only used in the case where CloseNotifier is not
|
||||||
// implemented by the parent ResponseWriter.
|
// implemented by the parent ResponseWriter.
|
||||||
|
@ -355,13 +335,3 @@ func (irw *instrumentedResponseWriter) Value(key interface{}) interface{} {
|
||||||
fallback:
|
fallback:
|
||||||
return irw.Context.Value(key)
|
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)
|
|
||||||
}
|
|
||||||
|
|
|
@ -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) {
|
func TestProxyManifestGetByTag(t *testing.T) {
|
||||||
truthConfig := configuration.Configuration{
|
truthConfig := configuration.Configuration{
|
||||||
Storage: configuration.Storage{
|
Storage: configuration.Storage{
|
||||||
|
|
|
@ -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.
|
// 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 {
|
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
|
// Get a channel that tells us if the client disconnects
|
||||||
var clientClosed <-chan bool
|
clientClosed := r.Context().Done()
|
||||||
if notifier, ok := responseWriter.(http.CloseNotifier); ok {
|
|
||||||
clientClosed = notifier.CloseNotify()
|
|
||||||
} else {
|
|
||||||
dcontext.GetLogger(ctx).Warnf("the ResponseWriter does not implement CloseNotifier (type: %T)", responseWriter)
|
|
||||||
}
|
|
||||||
|
|
||||||
var body = r.Body
|
var body = r.Body
|
||||||
if limit > 0 {
|
if limit > 0 {
|
||||||
body = http.MaxBytesReader(responseWriter, body, limit)
|
body = http.MaxBytesReader(responseWriter, body, limit)
|
||||||
|
|
Loading…
Reference in a new issue