Updated README

This commit is contained in:
yhirose 2019-07-23 08:05:51 -04:00
parent dd20e4d418
commit e0d327558d
2 changed files with 16 additions and 14 deletions

View File

@ -31,6 +31,10 @@ int main(void)
res.set_content(numbers, "text/plain");
});
svr.Get("/stop", [&](const Request& req, Response& res) {
svr.stop();
});
svr.listen("localhost", 1234);
}
```
@ -44,18 +48,6 @@ int port = svr.bind_to_any_port("0.0.0.0");
svr.listen_after_bind();
```
### Method Chain
```cpp
svr.Get("/get", [](const auto& req, auto& res) {
res.set_content("get", "text/plain");
})
.Post("/post", [](const auto& req, auto& res) {
res.set_content(req.body(), "text/plain");
})
.listen("localhost", 1234);
```
### Static File Server
```cpp
@ -114,6 +106,15 @@ int main(void)
}
```
### GET with HTTP headers
```c++
httplib::Headers headers = {
{ "Content-Length", "5" }
};
auto res = cli.Post("/validate-no-multiple-headers", headers, "hello", "text/plain");
```
### GET with Content Receiver
```c++

View File

@ -1157,8 +1157,9 @@ TEST_F(ServerTest, ArrayParam) {
}
TEST_F(ServerTest, NoMultipleHeaders) {
Headers headers;
headers.emplace("Content-Length", "5");
Headers headers = {
{ "Content-Length", "5" }
};
auto res = cli_.Post("/validate-no-multiple-headers", headers, "hello",
"text/plain");
ASSERT_TRUE(res != nullptr);