Update documentation to clarify progress callback usage and user data handling in examples

This commit is contained in:
yhirose
2026-03-13 22:54:29 -04:00
parent 3ad4a4243a
commit 2e61fd3e6e
4 changed files with 12 additions and 12 deletions

View File

@@ -60,7 +60,7 @@ For uploading large files, `make_file_provider()` comes in handy. It streams the
```cpp
httplib::Client cli("http://localhost:8080");
auto res = cli.Post("/upload", {}, {
auto res = cli.Post("/upload", {}, {}, {
httplib::make_file_provider("file", "/path/to/large-file.zip")
});
```
@@ -160,16 +160,16 @@ svr.set_post_routing_handler([](const auto &req, auto &res) {
});
```
Use `req.user_data` to pass data from middleware to handlers. This is useful for sharing things like decoded auth tokens.
Use `res.user_data` to pass data from middleware to handlers. This is useful for sharing things like decoded auth tokens.
```cpp
svr.set_pre_routing_handler([](const auto &req, auto &res) {
req.user_data["auth_user"] = std::string("alice");
res.user_data["auth_user"] = std::string("alice");
return httplib::Server::HandlerResponse::Unhandled;
});
svr.Get("/me", [](const auto &req, auto &res) {
auto user = std::any_cast<std::string>(req.user_data.at("auth_user"));
auto user = std::any_cast<std::string>(res.user_data.at("auth_user"));
res.set_content("Hello, " + user, "text/plain");
});
```