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
2e3419cc
Commit
2e3419cc
authored
Nov 10, 2014
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nghttpd: Cache formatted date string
parent
5b6b6dc1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
4 deletions
+30
-4
src/HttpServer.cc
src/HttpServer.cc
+30
-4
No files found.
src/HttpServer.cc
View file @
2e3419cc
...
...
@@ -224,6 +224,17 @@ void remove_stream_write_timeout(Stream *stream)
}
}
// namespace
namespace
{
std
::
shared_ptr
<
std
::
string
>
cached_date
;
}
// namespace
namespace
{
void
refresh_cb
(
evutil_socket_t
sig
,
short
events
,
void
*
arg
)
{
cached_date
=
std
::
make_shared
<
std
::
string
>
(
util
::
http_date
(
time
(
nullptr
)));
}
}
// namespace
namespace
{
void
fill_callback
(
nghttp2_session_callbacks
*
callbacks
,
const
Config
*
config
);
}
// namespace
...
...
@@ -612,7 +623,7 @@ int Http2Handler::submit_file_response(const std::string& status,
off_t
file_length
,
nghttp2_data_provider
*
data_prd
)
{
std
::
string
date_str
=
util
::
http_date
(
time
(
0
))
;
auto
date_str
=
cached_date
;
std
::
string
content_length
=
util
::
utos
(
file_length
);
std
::
string
last_modified_str
;
auto
nva
=
std
::
vector
<
nghttp2_nv
>
{
...
...
@@ -620,7 +631,7 @@ int Http2Handler::submit_file_response(const std::string& status,
http2
::
make_nv_ls
(
"server"
,
NGHTTPD_SERVER
),
http2
::
make_nv_ls
(
"content-length"
,
content_length
),
http2
::
make_nv_ll
(
"cache-control"
,
"max-age=3600"
),
http2
::
make_nv_ls
(
"date"
,
date_str
),
http2
::
make_nv_ls
(
"date"
,
*
date_str
),
};
if
(
last_modified
!=
0
)
{
last_modified_str
=
util
::
http_date
(
last_modified
);
...
...
@@ -636,11 +647,11 @@ int Http2Handler::submit_response
const
Headers
&
headers
,
nghttp2_data_provider
*
data_prd
)
{
std
::
string
date_str
=
util
::
http_date
(
time
(
0
))
;
auto
date_str
=
cached_date
;
auto
nva
=
std
::
vector
<
nghttp2_nv
>
{
http2
::
make_nv_ls
(
":status"
,
status
),
http2
::
make_nv_ls
(
"server"
,
NGHTTPD_SERVER
),
http2
::
make_nv_ls
(
"date"
,
date_str
)
http2
::
make_nv_ls
(
"date"
,
*
date_str
)
};
for
(
auto
&
nv
:
headers
)
{
nva
.
push_back
(
http2
::
make_nv
(
nv
.
name
,
nv
.
value
,
nv
.
no_index
));
...
...
@@ -1658,6 +1669,21 @@ int HttpServer::run()
std
::
cerr
<<
"Could not listen"
<<
std
::
endl
;
return
-
1
;
}
auto
refresh_ev
=
event_new
(
evbase
,
-
1
,
EV_PERSIST
,
refresh_cb
,
nullptr
);
if
(
!
refresh_ev
)
{
std
::
cerr
<<
"Could not add refresh timer"
<<
std
::
endl
;
return
-
1
;
}
timeval
refresh_timeout
=
{
1
,
0
};
if
(
event_add
(
refresh_ev
,
&
refresh_timeout
)
==
-
1
)
{
std
::
cerr
<<
"Adding refresh event failed"
<<
std
::
endl
;
return
-
1
;
}
cached_date
=
std
::
make_shared
<
std
::
string
>
(
util
::
http_date
(
time
(
nullptr
)));
event_base_loop
(
evbase
,
0
);
return
0
;
}
...
...
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