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
04996b28
Commit
04996b28
authored
Jan 29, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exported NewReplacer and NewRecorder
parent
261beb04
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
9 deletions
+9
-9
middleware/util_recorder.go
middleware/util_recorder.go
+2
-2
middleware/util_replacer.go
middleware/util_replacer.go
+7
-7
No files found.
middleware/util_recorder.go
View file @
04996b28
...
...
@@ -14,13 +14,13 @@ type responseRecorder struct {
size
int
}
//
n
ewResponseRecorder makes and returns a new responseRecorder,
//
N
ewResponseRecorder makes and returns a new responseRecorder,
// which captures the HTTP Status code from the ResponseWriter
// and also the length of the response body written through it.
// 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
n
ewResponseRecorder
(
w
http
.
ResponseWriter
)
*
responseRecorder
{
func
N
ewResponseRecorder
(
w
http
.
ResponseWriter
)
*
responseRecorder
{
return
&
responseRecorder
{
ResponseWriter
:
w
,
status
:
http
.
StatusOK
,
...
...
middleware/util_replacer.go
View file @
04996b28
...
...
@@ -10,14 +10,14 @@ import (
// replacer is a type which can replace placeholder
// substrings in a string with actual values from a
// http.Request and responseRecorder. Always use
//
n
ewReplacer to get one of these.
//
N
ewReplacer to get one of these.
type
replacer
map
[
string
]
string
//
n
ewReplacer makes a new replacer based on r and rw.
//
N
ewReplacer makes a new replacer based on r and rw.
// Do not create a new replacer until r and rw have all
// the needed values, because this function copies those
// values into the replacer.
func
n
ewReplacer
(
r
*
http
.
Request
,
rw
*
responseRecorder
)
replacer
{
func
N
ewReplacer
(
r
*
http
.
Request
,
rw
*
responseRecorder
)
replacer
{
rep
:=
replacer
{
"{method}"
:
r
.
Method
,
"{scheme}"
:
func
()
string
{
...
...
@@ -62,10 +62,10 @@ func newReplacer(r *http.Request, rw *responseRecorder) replacer {
// replace performs a replacement of values on s and returns
// the string with the replaced values.
func
(
r
replacer
)
r
eplace
(
s
string
)
string
{
func
(
r
replacer
)
R
eplace
(
s
string
)
string
{
for
placeholder
,
replacement
:=
range
r
{
if
replacement
==
""
{
replacement
=
e
mptyStringReplacer
replacement
=
E
mptyStringReplacer
}
s
=
strings
.
Replace
(
s
,
placeholder
,
replacement
,
-
1
)
}
...
...
@@ -76,7 +76,7 @@ func (r replacer) replace(s string) string {
endOffset
:=
idxStart
+
len
(
headerReplacer
)
idxEnd
:=
strings
.
Index
(
s
[
endOffset
:
],
"}"
)
if
idxEnd
>
-
1
{
s
=
s
[
:
idxStart
]
+
e
mptyStringReplacer
+
s
[
endOffset
+
idxEnd
+
1
:
]
s
=
s
[
:
idxStart
]
+
E
mptyStringReplacer
+
s
[
endOffset
+
idxEnd
+
1
:
]
}
else
{
break
}
...
...
@@ -87,5 +87,5 @@ func (r replacer) replace(s string) string {
const
(
timeFormat
=
"02/Jan/2006:15:04:05 -0700"
headerReplacer
=
"{>"
e
mptyStringReplacer
=
"-"
E
mptyStringReplacer
=
"-"
)
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