mirror of
https://github.com/nghttp2/nghttp2.git
synced 2025-12-07 10:38:53 +08:00
asio: Add serve_mux class to route incoming requet by path
serve_mux is direct port of ServeMux from go
This commit is contained in:
@@ -66,8 +66,7 @@ int main(int argc, char *argv[]) {
|
||||
server.tls(argv[4], argv[5]);
|
||||
}
|
||||
|
||||
server.listen("*", port,
|
||||
[&docroot](const request &req, const response &res) {
|
||||
server.handle("/", [&docroot](const request &req, const response &res) {
|
||||
auto path = percent_decode(req.uri().path);
|
||||
if (!check_path(path)) {
|
||||
res.write_head(404);
|
||||
@@ -99,6 +98,9 @@ int main(int argc, char *argv[]) {
|
||||
res.write_head(200, std::move(header));
|
||||
res.end(file_reader_from_fd(fd));
|
||||
});
|
||||
|
||||
server.listen("*", port);
|
||||
|
||||
} catch (std::exception &e) {
|
||||
std::cerr << "exception: " << e.what() << "\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user