Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
5b6b6dc1
Commit
5b6b6dc1
authored
Nov 10, 2014
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
src: Rewrite http_date
parent
d0271a90
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
6 deletions
+59
-6
src/shrpx-unittest.cc
src/shrpx-unittest.cc
+1
-0
src/util.cc
src/util.cc
+51
-6
src/util_test.cc
src/util_test.cc
+6
-0
src/util_test.h
src/util_test.h
+1
-0
No files found.
src/shrpx-unittest.cc
View file @
5b6b6dc1
...
...
@@ -123,6 +123,7 @@ int main(int argc, char* argv[])
!
CU_add_test
(
pSuite
,
"util_quote_string"
,
shrpx
::
test_util_quote_string
)
||
!
CU_add_test
(
pSuite
,
"util_utox"
,
shrpx
::
test_util_utox
)
||
!
CU_add_test
(
pSuite
,
"util_http_date"
,
shrpx
::
test_util_http_date
)
||
!
CU_add_test
(
pSuite
,
"gzip_inflate"
,
test_nghttp2_gzip_inflate
))
{
CU_cleanup_registry
();
return
CU_get_error
();
...
...
src/util.cc
View file @
5b6b6dc1
...
...
@@ -163,17 +163,62 @@ std::string quote_string(const std::string& target)
return
res
;
}
namespace
{
template
<
typename
Iterator
>
Iterator
cpydig
(
Iterator
d
,
int
n
,
size_t
len
)
{
auto
p
=
d
+
len
-
1
;
do
{
*
p
--
=
(
n
%
10
)
+
'0'
;
n
/=
10
;
}
while
(
p
>=
d
);
return
d
+
len
;
}
}
// namespace
namespace
{
const
char
*
MONTH
[]
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
const
char
*
DAY_OF_WEEK
[]
=
{
"Sun"
,
"Mon"
,
"Tue"
,
"Wed"
,
"Thu"
,
"Fri"
,
"Sat"
};
}
// namespace
std
::
string
http_date
(
time_t
t
)
{
char
buf
[
32
]
;
tm
tm
s
;
struct
tm
tms
;
std
::
string
re
s
;
if
(
gmtime_r
(
&
t
,
&
tms
)
==
nullptr
)
{
return
""
;
}
return
res
;
}
/* Sat, 27 Sep 2014 06:31:15 GMT */
res
.
resize
(
29
);
auto
p
=
std
::
begin
(
res
);
auto
s
=
DAY_OF_WEEK
[
tms
.
tm_wday
];
p
=
std
::
copy
(
s
,
s
+
3
,
p
);
*
p
++
=
','
;
*
p
++
=
' '
;
p
=
cpydig
(
p
,
tms
.
tm_mday
,
2
);
*
p
++
=
' '
;
s
=
MONTH
[
tms
.
tm_mon
];
p
=
std
::
copy
(
s
,
s
+
3
,
p
);
*
p
++
=
' '
;
p
=
cpydig
(
p
,
tms
.
tm_year
+
1900
,
4
);
*
p
++
=
' '
;
p
=
cpydig
(
p
,
tms
.
tm_hour
,
2
);
*
p
++
=
':'
;
p
=
cpydig
(
p
,
tms
.
tm_min
,
2
);
*
p
++
=
':'
;
p
=
cpydig
(
p
,
tms
.
tm_sec
,
2
);
s
=
" GMT"
;
p
=
std
::
copy
(
s
,
s
+
4
,
p
);
auto
rv
=
strftime
(
buf
,
sizeof
(
buf
),
"%a, %d %b %Y %H:%M:%S GMT"
,
&
tms
);
return
std
::
string
(
&
buf
[
0
],
&
buf
[
rv
]);
return
res
;
}
time_t
parse_http_date
(
const
std
::
string
&
s
)
...
...
src/util_test.cc
View file @
5b6b6dc1
...
...
@@ -118,4 +118,10 @@ void test_util_utox(void)
CU_ASSERT
(
"100000000"
==
util
::
utox
(
1LL
<<
32
));
}
void
test_util_http_date
(
void
)
{
CU_ASSERT
(
"Thu, 01 Jan 1970 00:00:00 GMT"
==
util
::
http_date
(
0
));
CU_ASSERT
(
"Wed, 29 Feb 2012 09:15:16 GMT"
==
util
::
http_date
(
1330506916
));
}
}
// namespace shrpx
src/util_test.h
View file @
5b6b6dc1
...
...
@@ -34,6 +34,7 @@ void test_util_to_base64(void);
void
test_util_percent_encode_token
(
void
);
void
test_util_quote_string
(
void
);
void
test_util_utox
(
void
);
void
test_util_http_date
(
void
);
}
// namespace shrpx
...
...
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