Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
bec130a5
Commit
bec130a5
authored
Feb 20, 2016
by
Benoit Benedetti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Recorder: Exporting ResponseRecorder #614
parent
09b7ce6c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
7 deletions
+17
-7
middleware/recorder.go
middleware/recorder.go
+16
-6
middleware/replacer.go
middleware/replacer.go
+1
-1
No files found.
middleware/recorder.go
View file @
bec130a5
...
...
@@ -14,7 +14,7 @@ import (
// to be written, however, in which case 200 must be assumed.
// It is best to have the constructor initialize this type
// with that default status code.
type
r
esponseRecorder
struct
{
type
R
esponseRecorder
struct
{
http
.
ResponseWriter
status
int
size
int
...
...
@@ -27,8 +27,8 @@ type responseRecorder struct {
// Because a status is not set unless WriteHeader is called
// explicitly, this constructor initializes with a status code
// of 200 to cover the default case.
func
NewResponseRecorder
(
w
http
.
ResponseWriter
)
*
r
esponseRecorder
{
return
&
r
esponseRecorder
{
func
NewResponseRecorder
(
w
http
.
ResponseWriter
)
*
R
esponseRecorder
{
return
&
R
esponseRecorder
{
ResponseWriter
:
w
,
status
:
http
.
StatusOK
,
start
:
time
.
Now
(),
...
...
@@ -37,14 +37,14 @@ func NewResponseRecorder(w http.ResponseWriter) *responseRecorder {
// WriteHeader records the status code and calls the
// underlying ResponseWriter's WriteHeader method.
func
(
r
*
r
esponseRecorder
)
WriteHeader
(
status
int
)
{
func
(
r
*
R
esponseRecorder
)
WriteHeader
(
status
int
)
{
r
.
status
=
status
r
.
ResponseWriter
.
WriteHeader
(
status
)
}
// Write is a wrapper that records the size of the body
// that gets written.
func
(
r
*
r
esponseRecorder
)
Write
(
buf
[]
byte
)
(
int
,
error
)
{
func
(
r
*
R
esponseRecorder
)
Write
(
buf
[]
byte
)
(
int
,
error
)
{
n
,
err
:=
r
.
ResponseWriter
.
Write
(
buf
)
if
err
==
nil
{
r
.
size
+=
n
...
...
@@ -52,9 +52,19 @@ func (r *responseRecorder) Write(buf []byte) (int, error) {
return
n
,
err
}
// Size is a Getter to size property
func
(
r
*
ResponseRecorder
)
Size
()
int
{
return
r
.
size
}
// Status is a Getter to status property
func
(
r
*
ResponseRecorder
)
Status
()
int
{
return
r
.
status
}
// Hijacker is a wrapper of http.Hijacker underearth if any,
// otherwise it just returns an error.
func
(
r
*
r
esponseRecorder
)
Hijack
()
(
net
.
Conn
,
*
bufio
.
ReadWriter
,
error
)
{
func
(
r
*
R
esponseRecorder
)
Hijack
()
(
net
.
Conn
,
*
bufio
.
ReadWriter
,
error
)
{
if
hj
,
ok
:=
r
.
ResponseWriter
.
(
http
.
Hijacker
);
ok
{
return
hj
.
Hijack
()
}
...
...
middleware/replacer.go
View file @
bec130a5
...
...
@@ -30,7 +30,7 @@ type replacer struct {
// values into the replacer. rr may be nil if it is not
// available. emptyValue should be the string that is used
// in place of empty string (can still be empty string).
func
NewReplacer
(
r
*
http
.
Request
,
rr
*
r
esponseRecorder
,
emptyValue
string
)
Replacer
{
func
NewReplacer
(
r
*
http
.
Request
,
rr
*
R
esponseRecorder
,
emptyValue
string
)
Replacer
{
rep
:=
replacer
{
replacements
:
map
[
string
]
string
{
"{method}"
:
r
.
Method
,
...
...
Write
Preview
Markdown
is supported
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