asio-lib: Make request_cb take const ref and use int64_t as http_date arg

This commit is contained in:
Tatsuhiro Tsujikawa 2014-10-28 01:01:48 +09:00
parent 1bd8f6a0e2
commit 0ef99b90d9
6 changed files with 18 additions and 11 deletions

View File

@ -42,7 +42,8 @@ HTTP/2 server looks like this:
server.listen
("*", 3000,
[](std::shared_ptr<request> req, std::shared_ptr<response> res)
[](const std::shared_ptr<request>& req,
const std::shared_ptr<response>& res)
{
res->write_head(200);
res->end("hello, world");
@ -85,7 +86,8 @@ SSL/TLS.
server.listen
("*", 3000,
[](std::shared_ptr<request> req, std::shared_ptr<response> res)
[](const std::shared_ptr<request>& req,
const std::shared_ptr<response>& res)
{
if(req->path() == "/" || req->path() == "/index.html") {
res->write_head(200);
@ -130,7 +132,8 @@ Server push is also supported.
server.listen
("*", 3000,
[](std::shared_ptr<request> req, std::shared_ptr<response> res)
[](const std::shared_ptr<request>& req,
const std::shared_ptr<response>& res)
{
if(req->path() == "/") {
req->push("GET", "/my.css");
@ -202,7 +205,8 @@ blocking task there. The example follows:
server.listen
("*", 3000,
[](std::shared_ptr<request> req, std::shared_ptr<response> res)
[](const std::shared_ptr<request>& req,
const std::shared_ptr<response>& res)
{
req->run_task
([res](channel& channel)

View File

@ -65,7 +65,8 @@ int main(int argc, char* argv[])
server.listen
("*", port,
[](std::shared_ptr<request> req, std::shared_ptr<response> res)
[](const std::shared_ptr<request>& req,
const std::shared_ptr<response>& res)
{
res->write_head(200, { header{ "foo", "bar" } });
res->end("hello, world");

View File

@ -69,7 +69,8 @@ int main(int argc, char* argv[])
server.listen
("*", port,
[&docroot](std::shared_ptr<request> req, std::shared_ptr<response> res)
[&docroot](const std::shared_ptr<request>& req,
const std::shared_ptr<response>& res)
{
auto path = percent_decode(req->path());
if(!check_path(path)) {

View File

@ -69,7 +69,8 @@ int main(int argc, char* argv[])
server.listen
("*", port,
[](std::shared_ptr<request> req, std::shared_ptr<response> res)
[](const std::shared_ptr<request>& req,
const std::shared_ptr<response>& res)
{
res->write_head(200);

View File

@ -204,7 +204,7 @@ std::string percent_decode(const std::string& s)
return util::percentDecode(std::begin(s), std::end(s));
}
std::string http_date(time_t t)
std::string http_date(int64_t t)
{
return util::http_date(t);
}

View File

@ -180,8 +180,8 @@ private:
// This is so called request callback. Called every time request is
// received.
typedef std::function<void(std::shared_ptr<request>,
std::shared_ptr<response>)> request_cb;
typedef std::function<void(const std::shared_ptr<request>&,
const std::shared_ptr<response>&)> request_cb;
class http2_impl;
@ -233,7 +233,7 @@ bool check_path(const std::string& path);
std::string percent_decode(const std::string& s);
// Returns HTTP date representation of current posix time |t|.
std::string http_date(time_t t);
std::string http_date(int64_t t);
} // namespace asio_http2