LibHTTP: Make HTTP method names more accessible

Previously you could only get the name of an HttpRequest::Method if you
already had an HttpRequest.
This commit is contained in:
Sam Atkins 2022-10-11 11:27:52 +01:00 committed by Andreas Kling
parent 84953c5020
commit 9b891a423b
Notes: sideshowbarker 2024-07-17 06:02:29 +09:00
2 changed files with 18 additions and 11 deletions

View file

@ -12,32 +12,37 @@
namespace HTTP {
String HttpRequest::method_name() const
String to_string(HttpRequest::Method method)
{
switch (m_method) {
case Method::GET:
switch (method) {
case HttpRequest::Method::GET:
return "GET";
case Method::HEAD:
case HttpRequest::Method::HEAD:
return "HEAD";
case Method::POST:
case HttpRequest::Method::POST:
return "POST";
case Method::DELETE:
case HttpRequest::Method::DELETE:
return "DELETE";
case Method::PATCH:
case HttpRequest::Method::PATCH:
return "PATCH";
case Method::OPTIONS:
case HttpRequest::Method::OPTIONS:
return "OPTIONS";
case Method::TRACE:
case HttpRequest::Method::TRACE:
return "TRACE";
case Method::CONNECT:
case HttpRequest::Method::CONNECT:
return "CONNECT";
case Method::PUT:
case HttpRequest::Method::PUT:
return "PUT";
default:
VERIFY_NOT_REACHED();
}
}
String HttpRequest::method_name() const
{
return to_string(m_method);
}
ByteBuffer HttpRequest::to_raw_request() const
{
StringBuilder builder;

View file

@ -73,4 +73,6 @@ private:
ByteBuffer m_body;
};
String to_string(HttpRequest::Method);
}