Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
traefik
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
containous
traefik
Commits
f1b91a11
Unverified
Commit
f1b91a11
authored
2 years ago
by
Simon Delicata
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Create a new capture instance for each incoming request
Co-authored-by:
Romain
<
rtribotte@users.noreply.github.com
>
parent
35d8281f
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/middlewares/capture/capture.go
+23
-14
23 additions, 14 deletions
pkg/middlewares/capture/capture.go
with
23 additions
and
14 deletions
pkg/middlewares/capture/capture.go
+
23
−
14
View file @
f1b91a11
...
...
@@ -39,11 +39,14 @@ type key string
const
capturedData
key
=
"capturedData"
// Wrap returns a new handler that inserts a Capture into the given handler.
// Wrap returns a new handler that inserts a Capture into the given handler
for each incoming request
.
// It satisfies the alice.Constructor type.
func
Wrap
(
handler
http
.
Handler
)
(
http
.
Handler
,
error
)
{
c
:=
Capture
{}
return
c
.
Reset
(
handler
),
nil
func
Wrap
(
next
http
.
Handler
)
(
http
.
Handler
,
error
)
{
return
http
.
HandlerFunc
(
func
(
rw
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
c
:=
&
Capture
{}
newRW
,
newReq
:=
c
.
renew
(
rw
,
req
)
next
.
ServeHTTP
(
newRW
,
newReq
)
}),
nil
}
// FromContext returns the Capture value found in ctx, or an empty Capture otherwise.
...
...
@@ -68,6 +71,7 @@ type Capture struct {
// NeedsReset returns whether the given http.ResponseWriter is the capture's probe.
func
(
c
*
Capture
)
NeedsReset
(
rw
http
.
ResponseWriter
)
bool
{
// This comparison is naive.
return
c
.
rw
!=
rw
}
...
...
@@ -75,18 +79,23 @@ func (c *Capture) NeedsReset(rw http.ResponseWriter) bool {
// them when deferring to next.
func
(
c
*
Capture
)
Reset
(
next
http
.
Handler
)
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
rw
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
ctx
:=
context
.
WithValue
(
req
.
Context
(),
capturedData
,
c
)
newReq
:=
req
.
WithContext
(
ctx
)
newRW
,
newReq
:=
c
.
renew
(
rw
,
req
)
next
.
ServeHTTP
(
newRW
,
newReq
)
})
}
if
newReq
.
Body
!=
nil
{
readCounter
:=
&
readCounter
{
source
:
newReq
.
Body
}
c
.
rr
=
readCounter
newReq
.
Body
=
readCounter
}
c
.
rw
=
newResponseWriter
(
rw
)
func
(
c
*
Capture
)
renew
(
rw
http
.
ResponseWriter
,
req
*
http
.
Request
)
(
http
.
ResponseWriter
,
*
http
.
Request
)
{
ctx
:=
context
.
WithValue
(
req
.
Context
(),
capturedData
,
c
)
newReq
:=
req
.
WithContext
(
ctx
)
next
.
ServeHTTP
(
c
.
rw
,
newReq
)
})
if
newReq
.
Body
!=
nil
{
readCounter
:=
&
readCounter
{
source
:
newReq
.
Body
}
c
.
rr
=
readCounter
newReq
.
Body
=
readCounter
}
c
.
rw
=
newResponseWriter
(
rw
)
return
c
.
rw
,
newReq
}
func
(
c
*
Capture
)
ResponseSize
()
int64
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment