mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-10 09:43:51 +00:00
Updated README
This commit is contained in:
parent
dd20e4d418
commit
e0d327558d
25
README.md
25
README.md
@ -31,6 +31,10 @@ int main(void)
|
|||||||
res.set_content(numbers, "text/plain");
|
res.set_content(numbers, "text/plain");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
svr.Get("/stop", [&](const Request& req, Response& res) {
|
||||||
|
svr.stop();
|
||||||
|
});
|
||||||
|
|
||||||
svr.listen("localhost", 1234);
|
svr.listen("localhost", 1234);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -44,18 +48,6 @@ int port = svr.bind_to_any_port("0.0.0.0");
|
|||||||
svr.listen_after_bind();
|
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
|
### Static File Server
|
||||||
|
|
||||||
```cpp
|
```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
|
### GET with Content Receiver
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
|
@ -1157,8 +1157,9 @@ TEST_F(ServerTest, ArrayParam) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ServerTest, NoMultipleHeaders) {
|
TEST_F(ServerTest, NoMultipleHeaders) {
|
||||||
Headers headers;
|
Headers headers = {
|
||||||
headers.emplace("Content-Length", "5");
|
{ "Content-Length", "5" }
|
||||||
|
};
|
||||||
auto res = cli_.Post("/validate-no-multiple-headers", headers, "hello",
|
auto res = cli_.Post("/validate-no-multiple-headers", headers, "hello",
|
||||||
"text/plain");
|
"text/plain");
|
||||||
ASSERT_TRUE(res != nullptr);
|
ASSERT_TRUE(res != nullptr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user