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
9edc16e4
Commit
9edc16e4
authored
Aug 28, 2018
by
Makeev Ivan
Committed by
Toby Allen
Aug 28, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding {when_unix_ms} requests placeholder (unix timestamp with a milliseconds precision) (#2260)
parent
73273c5b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
2 deletions
+9
-2
caddyhttp/httpserver/replacer.go
caddyhttp/httpserver/replacer.go
+7
-1
caddyhttp/httpserver/replacer_test.go
caddyhttp/httpserver/replacer_test.go
+2
-1
No files found.
caddyhttp/httpserver/replacer.go
View file @
9edc16e4
...
...
@@ -372,6 +372,8 @@ func (r *replacer) getSubstitution(key string) string {
return
now
()
.
UTC
()
.
Format
(
timeFormatISOUTC
)
case
"{when_unix}"
:
return
strconv
.
FormatInt
(
now
()
.
Unix
(),
10
)
case
"{when_unix_ms}"
:
return
strconv
.
FormatInt
(
nanoToMilliseconds
(
now
()
.
UnixNano
()),
10
)
case
"{file}"
:
_
,
file
:=
path
.
Split
(
r
.
request
.
URL
.
Path
)
return
file
...
...
@@ -521,9 +523,13 @@ func (r *replacer) getSubstitution(key string) string {
return
r
.
emptyValue
}
func
nanoToMilliseconds
(
d
int64
)
int64
{
return
d
/
1e6
}
// convertToMilliseconds returns the number of milliseconds in the given duration
func
convertToMilliseconds
(
d
time
.
Duration
)
int64
{
return
d
.
Nanoseconds
()
/
1e6
return
nanoToMilliseconds
(
d
.
Nanoseconds
())
}
// Set sets key to value in the r.customReplacements map.
...
...
caddyhttp/httpserver/replacer_test.go
View file @
9edc16e4
...
...
@@ -86,7 +86,7 @@ func TestReplace(t *testing.T) {
old
:=
now
now
=
func
()
time
.
Time
{
return
time
.
Date
(
2006
,
1
,
2
,
15
,
4
,
5
,
02
,
time
.
FixedZone
(
"hardcoded"
,
-
7
))
return
time
.
Date
(
2006
,
1
,
2
,
15
,
4
,
5
,
99999999
,
time
.
FixedZone
(
"hardcoded"
,
-
7
))
}
defer
func
()
{
now
=
old
...
...
@@ -102,6 +102,7 @@ func TestReplace(t *testing.T) {
{
"{when}"
,
"02/Jan/2006:15:04:05 +0000"
},
{
"{when_iso}"
,
"2006-01-02T15:04:12Z"
},
{
"{when_unix}"
,
"1136214252"
},
{
"{when_unix_ms}"
,
"1136214252099"
},
{
"The Custom header is {>Custom}."
,
"The Custom header is foobarbaz."
},
{
"The CustomAdd header is {>CustomAdd}."
,
"The CustomAdd header is caddy."
},
{
"The Custom response header is {<Custom}."
,
"The Custom response header is CustomResponseHeader."
},
...
...
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