Reformat source code in libnghttp2_asio.rst
This commit is contained in:
parent
f2cd057e89
commit
30499005f8
|
@ -36,15 +36,11 @@ HTTP/2 server looks like this:
|
|||
using namespace nghttp2::asio_http2;
|
||||
using namespace nghttp2::asio_http2::server;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
http2 server;
|
||||
|
||||
server.listen
|
||||
("*", 3000,
|
||||
[](const std::shared_ptr<request>& req,
|
||||
const std::shared_ptr<response>& res)
|
||||
{
|
||||
server.listen("*", 3000, [](const std::shared_ptr<request> &req,
|
||||
const std::shared_ptr<response> &res) {
|
||||
res->write_head(200);
|
||||
res->end("hello, world");
|
||||
});
|
||||
|
@ -78,17 +74,13 @@ SSL/TLS.
|
|||
using namespace nghttp2::asio_http2;
|
||||
using namespace nghttp2::asio_http2::server;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
http2 server;
|
||||
|
||||
server.tls("server.key", "server.crt");
|
||||
|
||||
server.listen
|
||||
("*", 3000,
|
||||
[](const std::shared_ptr<request>& req,
|
||||
const std::shared_ptr<response>& res)
|
||||
{
|
||||
server.listen("*", 3000, [](const std::shared_ptr<request> &req,
|
||||
const std::shared_ptr<response> &res) {
|
||||
if (req->path() == "/" || req->path() == "/index.html") {
|
||||
res->write_head(200);
|
||||
res->end(file_reader("index.html"));
|
||||
|
@ -124,17 +116,13 @@ Server push is also supported.
|
|||
using namespace nghttp2::asio_http2;
|
||||
using namespace nghttp2::asio_http2::server;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
http2 server;
|
||||
|
||||
server.tls("server.key", "server.crt");
|
||||
|
||||
server.listen
|
||||
("*", 3000,
|
||||
[](const std::shared_ptr<request>& req,
|
||||
const std::shared_ptr<response>& res)
|
||||
{
|
||||
server.listen("*", 3000, [](const std::shared_ptr<request> &req,
|
||||
const std::shared_ptr<response> &res) {
|
||||
if (req->path() == "/") {
|
||||
req->push("GET", "/my.css");
|
||||
|
||||
|
@ -197,20 +185,14 @@ blocking task there. The example follows:
|
|||
using namespace nghttp2::asio_http2;
|
||||
using namespace nghttp2::asio_http2::server;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
http2 server;
|
||||
|
||||
server.num_concurrent_tasks(16);
|
||||
|
||||
server.listen
|
||||
("*", 3000,
|
||||
[](const std::shared_ptr<request>& req,
|
||||
const std::shared_ptr<response>& res)
|
||||
{
|
||||
req->run_task
|
||||
([res](channel& channel)
|
||||
{
|
||||
server.listen("*", 3000, [](const std::shared_ptr<request> &req,
|
||||
const std::shared_ptr<response> &res) {
|
||||
req->run_task([res](channel &channel) {
|
||||
// executed in different thread than the thread where
|
||||
// request callback was executed.
|
||||
|
||||
|
@ -219,9 +201,7 @@ blocking task there. The example follows:
|
|||
|
||||
sleep(1);
|
||||
|
||||
channel.post
|
||||
([res]()
|
||||
{
|
||||
channel.post([res]() {
|
||||
// executed in the same thread where request callback
|
||||
// was executed.
|
||||
res->write_head(200);
|
||||
|
|
Loading…
Reference in New Issue