From 9b891a423bbb2e7d047b37feda0ede56cfa9353a Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 11 Oct 2022 11:27:52 +0100 Subject: [PATCH] LibHTTP: Make HTTP method names more accessible Previously you could only get the name of an HttpRequest::Method if you already had an HttpRequest. --- Userland/Libraries/LibHTTP/HttpRequest.cpp | 27 +++++++++++++--------- Userland/Libraries/LibHTTP/HttpRequest.h | 2 ++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibHTTP/HttpRequest.cpp b/Userland/Libraries/LibHTTP/HttpRequest.cpp index bf74a0e800..e421c369b7 100644 --- a/Userland/Libraries/LibHTTP/HttpRequest.cpp +++ b/Userland/Libraries/LibHTTP/HttpRequest.cpp @@ -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; diff --git a/Userland/Libraries/LibHTTP/HttpRequest.h b/Userland/Libraries/LibHTTP/HttpRequest.h index 716df9cdf1..2f58a4bba2 100644 --- a/Userland/Libraries/LibHTTP/HttpRequest.h +++ b/Userland/Libraries/LibHTTP/HttpRequest.h @@ -73,4 +73,6 @@ private: ByteBuffer m_body; }; +String to_string(HttpRequest::Method); + }