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
09aad777
Commit
09aad777
authored
Mar 26, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Proper host/port splitting; also log file perms
parent
da72a5fb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
12 deletions
+14
-12
middleware/log/log.go
middleware/log/log.go
+1
-1
middleware/replacer.go
middleware/replacer.go
+13
-11
No files found.
middleware/log/log.go
View file @
09aad777
...
...
@@ -43,7 +43,7 @@ func New(c middleware.Controller) (middleware.Middleware, error) {
}
else
if
outputFile
==
"stderr"
{
file
=
os
.
Stderr
}
else
{
file
,
err
=
os
.
OpenFile
(
outputFile
,
os
.
O_RDWR
|
os
.
O_CREATE
|
os
.
O_APPEND
,
06
66
)
file
,
err
=
os
.
OpenFile
(
outputFile
,
os
.
O_RDWR
|
os
.
O_CREATE
|
os
.
O_APPEND
,
06
44
)
if
err
!=
nil
{
return
err
}
...
...
middleware/replacer.go
View file @
09aad777
package
middleware
import
(
"net"
"net/http"
"strconv"
"strings"
...
...
@@ -13,11 +14,11 @@ import (
// NewReplacer to get one of these.
type
replacer
map
[
string
]
string
// NewReplacer makes a new replacer based on r and r
w
.
// Do not create a new replacer until r and r
w
have all
// NewReplacer makes a new replacer based on r and r
r
.
// Do not create a new replacer until r and r
r
have all
// the needed values, because this function copies those
// values into the replacer.
func
NewReplacer
(
r
*
http
.
Request
,
r
w
*
responseRecorder
)
replacer
{
func
NewReplacer
(
r
*
http
.
Request
,
r
r
*
responseRecorder
)
replacer
{
rep
:=
replacer
{
"{method}"
:
r
.
Method
,
"{scheme}"
:
func
()
string
{
...
...
@@ -32,24 +33,25 @@ func NewReplacer(r *http.Request, rw *responseRecorder) replacer {
"{fragment}"
:
r
.
URL
.
Fragment
,
"{proto}"
:
r
.
Proto
,
"{remote}"
:
func
()
string
{
if
idx
:=
strings
.
Index
(
r
.
RemoteAddr
,
":"
);
idx
>
-
1
{
return
r
.
RemoteAddr
[
:
idx
]
// IP address only
}
else
{
host
,
_
,
err
:=
net
.
SplitHostPort
(
r
.
RemoteAddr
)
if
err
!=
nil
{
return
r
.
RemoteAddr
}
return
host
}(),
"{port}"
:
func
()
string
{
if
idx
:=
strings
.
Index
(
r
.
Host
,
":"
);
idx
>
-
1
{
return
r
.
Host
[
idx
+
1
:
]
// port only
_
,
port
,
err
:=
net
.
SplitHostPort
(
r
.
RemoteAddr
)
if
err
!=
nil
{
return
""
}
return
""
return
port
}(),
"{uri}"
:
r
.
RequestURI
,
"{when}"
:
func
()
string
{
return
time
.
Now
()
.
Format
(
timeFormat
)
}(),
"{status}"
:
strconv
.
Itoa
(
r
w
.
status
),
"{size}"
:
strconv
.
Itoa
(
r
w
.
size
),
"{status}"
:
strconv
.
Itoa
(
r
r
.
status
),
"{size}"
:
strconv
.
Itoa
(
r
r
.
size
),
}
// Header placeholders
...
...
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