1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 10:15:07 +00:00

LibHTTP+RequestServer: Recognize more HTTP methods

Previously it would default to GET for all of these and cause the
Discord API to return Method Not Allowed errors for certain endpoints.
This commit is contained in:
Luke Wilde 2022-06-27 21:39:03 +01:00 committed by Linus Groh
parent 1ceba560f4
commit cd9864bbf1
3 changed files with 45 additions and 1 deletions

View file

@ -21,6 +21,18 @@ String HttpRequest::method_name() const
return "HEAD";
case Method::POST:
return "POST";
case Method::DELETE:
return "DELETE";
case Method::PATCH:
return "PATCH";
case Method::OPTIONS:
return "OPTIONS";
case Method::TRACE:
return "TRACE";
case Method::CONNECT:
return "CONNECT";
case Method::PUT:
return "PUT";
default:
VERIFY_NOT_REACHED();
}
@ -155,6 +167,18 @@ Optional<HttpRequest> HttpRequest::from_raw_request(ReadonlyBytes raw_request)
request.m_method = Method::HEAD;
else if (method == "POST")
request.m_method = Method::POST;
else if (method == "DELETE")
request.set_method(HTTP::HttpRequest::Method::DELETE);
else if (method == "PATCH")
request.set_method(HTTP::HttpRequest::Method::PATCH);
else if (method == "OPTIONS")
request.set_method(HTTP::HttpRequest::Method::OPTIONS);
else if (method == "TRACE")
request.set_method(HTTP::HttpRequest::Method::TRACE);
else if (method == "CONNECT")
request.set_method(HTTP::HttpRequest::Method::CONNECT);
else if (method == "PUT")
request.set_method(HTTP::HttpRequest::Method::PUT);
else
return {};