Skip to content

Commit dcdb0d0

Browse files
committed
Fixed PRI request problem
1 parent 1f86e41 commit dcdb0d0

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

httplib.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,7 +2322,7 @@ inline void Server::stop() {
23222322
}
23232323

23242324
inline bool Server::parse_request_line(const char *s, Request &req) {
2325-
static std::regex re("(GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS) "
2325+
static std::regex re("(GET|HEAD|POST|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH|PRI) "
23262326
"(([^?]+)(?:\\?(.+?))?) (HTTP/1\\.[01])\r\n");
23272327

23282328
std::cmatch m;
@@ -2614,13 +2614,15 @@ inline bool Server::routing(Request &req, Response &res) {
26142614
return dispatch_request(req, res, post_handlers_);
26152615
} else if (req.method == "PUT") {
26162616
return dispatch_request(req, res, put_handlers_);
2617-
} else if (req.method == "PATCH") {
2618-
return dispatch_request(req, res, patch_handlers_);
26192617
} else if (req.method == "DELETE") {
26202618
return dispatch_request(req, res, delete_handlers_);
26212619
} else if (req.method == "OPTIONS") {
26222620
return dispatch_request(req, res, options_handlers_);
2621+
} else if (req.method == "PATCH") {
2622+
return dispatch_request(req, res, patch_handlers_);
26232623
}
2624+
2625+
res.status = 400;
26242626
return false;
26252627
}
26262628

@@ -2682,7 +2684,7 @@ Server::process_request(Stream &strm, bool last_connection,
26822684
req.set_header("REMOTE_ADDR", strm.get_remote_addr());
26832685

26842686
// Body
2685-
if (req.method == "POST" || req.method == "PUT" || req.method == "PATCH") {
2687+
if (req.method == "POST" || req.method == "PUT" || req.method == "PATCH" || req.method == "PRI") {
26862688
if (!detail::read_content(strm, req, payload_max_length_, res.status,
26872689
Progress(), [&](const char *buf, size_t n) {
26882690
if (req.body.size() + n > req.body.max_size()) {
@@ -2720,7 +2722,7 @@ Server::process_request(Stream &strm, bool last_connection,
27202722
if (routing(req, res)) {
27212723
if (res.status == -1) { res.status = req.ranges.empty() ? 200 : 206; }
27222724
} else {
2723-
res.status = 404;
2725+
if (res.status == -1) { res.status = 404; }
27242726
}
27252727

27262728
return write_response(strm, last_connection, req, res);

test/test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ TEST_F(ServerTest, NoMultipleHeaders) {
13961396
TEST_F(ServerTest, HTTP2Magic) {
13971397
Request req;
13981398
req.method = "PRI";
1399-
req.path = "/";
1399+
req.path = "*";
14001400
req.body = "SM";
14011401

14021402
auto res = std::make_shared<Response>();

0 commit comments

Comments
 (0)