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
Łukasz Nowak
caddy
Commits
6c847d07
Commit
6c847d07
authored
Jun 07, 2016
by
Gustavo Chaín
Committed by
Matt Holt
Jun 07, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New {request} placeholder to log entire requests (sans body) (#871)
Add a {request} placeholder to the replacer. Closes #858.
parent
01e05afa
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
0 deletions
+20
-0
caddyhttp/httpserver/replacer.go
caddyhttp/httpserver/replacer.go
+17
-0
caddyhttp/httpserver/replacer_test.go
caddyhttp/httpserver/replacer_test.go
+3
-0
No files found.
caddyhttp/httpserver/replacer.go
View file @
6c847d07
...
@@ -3,6 +3,7 @@ package httpserver
...
@@ -3,6 +3,7 @@ package httpserver
import
(
import
(
"net"
"net"
"net/http"
"net/http"
"net/http/httputil"
"net/url"
"net/url"
"os"
"os"
"path"
"path"
...
@@ -11,6 +12,14 @@ import (
...
@@ -11,6 +12,14 @@ import (
"time"
"time"
)
)
// requestReplacer is a strings.Replacer which is used to
// encode literal \r and \n characters and keep everything
// on one line
var
requestReplacer
=
strings
.
NewReplacer
(
"
\r
"
,
"
\\
r"
,
"
\n
"
,
"
\\
n"
,
)
// Replacer is a type which can replace placeholder
// Replacer is a type which can replace placeholder
// substrings in a string with actual values from a
// substrings in a string with actual values from a
// http.Request and ResponseRecorder. Always use
// http.Request and ResponseRecorder. Always use
...
@@ -95,6 +104,14 @@ func NewReplacer(r *http.Request, rr *ResponseRecorder, emptyValue string) Repla
...
@@ -95,6 +104,14 @@ func NewReplacer(r *http.Request, rr *ResponseRecorder, emptyValue string) Repla
dir
,
_
:=
path
.
Split
(
r
.
URL
.
Path
)
dir
,
_
:=
path
.
Split
(
r
.
URL
.
Path
)
return
dir
return
dir
}(),
}(),
"{request}"
:
func
()
string
{
dump
,
err
:=
httputil
.
DumpRequest
(
r
,
false
)
if
err
!=
nil
{
return
""
}
return
requestReplacer
.
Replace
(
string
(
dump
))
}(),
},
},
emptyValue
:
emptyValue
,
emptyValue
:
emptyValue
,
}
}
...
...
caddyhttp/httpserver/replacer_test.go
View file @
6c847d07
...
@@ -74,6 +74,9 @@ func TestReplace(t *testing.T) {
...
@@ -74,6 +74,9 @@ func TestReplace(t *testing.T) {
if
expected
,
actual
:=
"The Custom header is foobarbaz."
,
repl
.
Replace
(
"The Custom header is {>Custom}."
);
expected
!=
actual
{
if
expected
,
actual
:=
"The Custom header is foobarbaz."
,
repl
.
Replace
(
"The Custom header is {>Custom}."
);
expected
!=
actual
{
t
.
Errorf
(
"{>Custom} replacement: expected '%s', got '%s'"
,
expected
,
actual
)
t
.
Errorf
(
"{>Custom} replacement: expected '%s', got '%s'"
,
expected
,
actual
)
}
}
if
expected
,
actual
:=
"The request is POST / HTTP/1.1
\\
r
\\
nHost: localhost
\\
r
\\
nCustom: foobarbaz
\\
r
\\
nShorterval: 1
\\
r
\\
n
\\
r
\\
n."
,
repl
.
Replace
(
"The request is {request}."
);
expected
!=
actual
{
t
.
Errorf
(
"{request} replacement: expected '%s', got '%s'"
,
expected
,
actual
)
}
// Test header case-insensitivity
// Test header case-insensitivity
if
expected
,
actual
:=
"The cUsToM header is foobarbaz..."
,
repl
.
Replace
(
"The cUsToM header is {>cUsToM}..."
);
expected
!=
actual
{
if
expected
,
actual
:=
"The cUsToM header is foobarbaz..."
,
repl
.
Replace
(
"The cUsToM header is {>cUsToM}..."
);
expected
!=
actual
{
...
...
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