Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Plural
platform
distribution
Commits
bd41413d
Commit
bd41413d
authored
6 years ago
by
David Wu
Browse files
Options
Download
Email Patches
Plain Diff
remove closenotifier
Signed-off-by:
David Wu
<
david.wu@docker.com
>
parent
166874ad
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
context/http.go
+0
-30
context/http.go
registry/handlers/api_test.go
+0
-29
registry/handlers/api_test.go
registry/handlers/helpers.go
+1
-7
registry/handlers/helpers.go
with
1 addition
and
66 deletions
+1
-66
context/http.go
+
0
-
30
View file @
bd41413d
...
...
@@ -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
,
...
...
@@ -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.
...
...
@@ -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
)
}
This diff is collapsed.
Click to expand it.
registry/handlers/api_test.go
+
0
-
29
View file @
bd41413d
...
...
@@ -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
{
...
...
This diff is collapsed.
Click to expand it.
registry/handlers/helpers.go
+
1
-
7
View file @
bd41413d
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help