mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:47:34 +00:00
LibHTTP: Make HttpRequest
return its method name as a StringView
This commit is contained in:
parent
163ddf1d73
commit
b46667639f
3 changed files with 16 additions and 16 deletions
|
@ -12,35 +12,35 @@
|
||||||
|
|
||||||
namespace HTTP {
|
namespace HTTP {
|
||||||
|
|
||||||
DeprecatedString to_deprecated_string(HttpRequest::Method method)
|
StringView to_string_view(HttpRequest::Method method)
|
||||||
{
|
{
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case HttpRequest::Method::GET:
|
case HttpRequest::Method::GET:
|
||||||
return "GET";
|
return "GET"sv;
|
||||||
case HttpRequest::Method::HEAD:
|
case HttpRequest::Method::HEAD:
|
||||||
return "HEAD";
|
return "HEAD"sv;
|
||||||
case HttpRequest::Method::POST:
|
case HttpRequest::Method::POST:
|
||||||
return "POST";
|
return "POST"sv;
|
||||||
case HttpRequest::Method::DELETE:
|
case HttpRequest::Method::DELETE:
|
||||||
return "DELETE";
|
return "DELETE"sv;
|
||||||
case HttpRequest::Method::PATCH:
|
case HttpRequest::Method::PATCH:
|
||||||
return "PATCH";
|
return "PATCH"sv;
|
||||||
case HttpRequest::Method::OPTIONS:
|
case HttpRequest::Method::OPTIONS:
|
||||||
return "OPTIONS";
|
return "OPTIONS"sv;
|
||||||
case HttpRequest::Method::TRACE:
|
case HttpRequest::Method::TRACE:
|
||||||
return "TRACE";
|
return "TRACE"sv;
|
||||||
case HttpRequest::Method::CONNECT:
|
case HttpRequest::Method::CONNECT:
|
||||||
return "CONNECT";
|
return "CONNECT"sv;
|
||||||
case HttpRequest::Method::PUT:
|
case HttpRequest::Method::PUT:
|
||||||
return "PUT";
|
return "PUT"sv;
|
||||||
default:
|
default:
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString HttpRequest::method_name() const
|
StringView HttpRequest::method_name() const
|
||||||
{
|
{
|
||||||
return to_deprecated_string(m_method);
|
return to_string_view(m_method);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<ByteBuffer> HttpRequest::to_raw_request() const
|
ErrorOr<ByteBuffer> HttpRequest::to_raw_request() const
|
||||||
|
|
|
@ -79,7 +79,7 @@ public:
|
||||||
ByteBuffer const& body() const { return m_body; }
|
ByteBuffer const& body() const { return m_body; }
|
||||||
void set_body(ByteBuffer&& body) { m_body = move(body); }
|
void set_body(ByteBuffer&& body) { m_body = move(body); }
|
||||||
|
|
||||||
DeprecatedString method_name() const;
|
StringView method_name() const;
|
||||||
ErrorOr<ByteBuffer> to_raw_request() const;
|
ErrorOr<ByteBuffer> to_raw_request() const;
|
||||||
|
|
||||||
void set_headers(HashMap<DeprecatedString, DeprecatedString> const&);
|
void set_headers(HashMap<DeprecatedString, DeprecatedString> const&);
|
||||||
|
@ -96,6 +96,6 @@ private:
|
||||||
ByteBuffer m_body;
|
ByteBuffer m_body;
|
||||||
};
|
};
|
||||||
|
|
||||||
DeprecatedString to_deprecated_string(HttpRequest::Method);
|
StringView to_string_view(HttpRequest::Method);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ static constexpr auto s_webdriver_endpoints = Array {
|
||||||
// https://w3c.github.io/webdriver/#dfn-match-a-request
|
// https://w3c.github.io/webdriver/#dfn-match-a-request
|
||||||
static ErrorOr<MatchedRoute, Error> match_route(HTTP::HttpRequest const& request)
|
static ErrorOr<MatchedRoute, Error> match_route(HTTP::HttpRequest const& request)
|
||||||
{
|
{
|
||||||
dbgln_if(WEBDRIVER_DEBUG, "match_route({}, {})", HTTP::to_deprecated_string(request.method()), request.resource());
|
dbgln_if(WEBDRIVER_DEBUG, "match_route({}, {})", HTTP::to_string_view(request.method()), request.resource());
|
||||||
|
|
||||||
auto request_path = request.resource().view();
|
auto request_path = request.resource().view();
|
||||||
Vector<String> parameters;
|
Vector<String> parameters;
|
||||||
|
@ -129,7 +129,7 @@ static ErrorOr<MatchedRoute, Error> match_route(HTTP::HttpRequest const& request
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto const& route : s_webdriver_endpoints) {
|
for (auto const& route : s_webdriver_endpoints) {
|
||||||
dbgln_if(WEBDRIVER_DEBUG, "- Checking {} {}", HTTP::to_deprecated_string(route.method), route.path);
|
dbgln_if(WEBDRIVER_DEBUG, "- Checking {} {}", HTTP::to_string_view(route.method), route.path);
|
||||||
if (route.method != request.method())
|
if (route.method != request.method())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue