summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-12-19 17:38:33 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-19 18:29:13 +0100
commit48d74c53565f6bd87e70430ea5b0bc7e6dedb957 (patch)
treef144a49e40fdc65f7056dc56417c347628dcb51c
parente517505e35997d3e707b2332be57c5662b330674 (diff)
downloadserenity-48d74c53565f6bd87e70430ea5b0bc7e6dedb957.zip
LibHTTP: Make HTTPRequest::from_raw_request() take a ReadonlyBytes
This allows us to get rid of some ByteBuffer::wrap() usage.
-rw-r--r--Libraries/LibHTTP/HttpRequest.cpp2
-rw-r--r--Libraries/LibHTTP/HttpRequest.h2
-rw-r--r--Meta/Lagom/Fuzzers/FuzzHttpRequest.cpp2
-rw-r--r--Services/WebServer/Client.cpp4
-rw-r--r--Services/WebServer/Client.h2
5 files changed, 6 insertions, 6 deletions
diff --git a/Libraries/LibHTTP/HttpRequest.cpp b/Libraries/LibHTTP/HttpRequest.cpp
index 0793b13fe2..e5eaeefa97 100644
--- a/Libraries/LibHTTP/HttpRequest.cpp
+++ b/Libraries/LibHTTP/HttpRequest.cpp
@@ -79,7 +79,7 @@ ByteBuffer HttpRequest::to_raw_request() const
return builder.to_byte_buffer();
}
-Optional<HttpRequest> HttpRequest::from_raw_request(const ByteBuffer& raw_request)
+Optional<HttpRequest> HttpRequest::from_raw_request(ReadonlyBytes raw_request)
{
enum class State {
InMethod,
diff --git a/Libraries/LibHTTP/HttpRequest.h b/Libraries/LibHTTP/HttpRequest.h
index 7ef91d9968..8c1b158aa8 100644
--- a/Libraries/LibHTTP/HttpRequest.h
+++ b/Libraries/LibHTTP/HttpRequest.h
@@ -69,7 +69,7 @@ public:
void set_headers(const HashMap<String, String>&);
- static Optional<HttpRequest> from_raw_request(const ByteBuffer&);
+ static Optional<HttpRequest> from_raw_request(ReadonlyBytes);
private:
URL m_url;
diff --git a/Meta/Lagom/Fuzzers/FuzzHttpRequest.cpp b/Meta/Lagom/Fuzzers/FuzzHttpRequest.cpp
index 7eb4fb5ac5..78620d8cdb 100644
--- a/Meta/Lagom/Fuzzers/FuzzHttpRequest.cpp
+++ b/Meta/Lagom/Fuzzers/FuzzHttpRequest.cpp
@@ -30,7 +30,7 @@
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
- auto request_wrapper = HTTP::HttpRequest::from_raw_request(ByteBuffer::wrap(const_cast<u8*>(data), size));
+ auto request_wrapper = HTTP::HttpRequest::from_raw_request(ReadonlyBytes { data, size });
if (!request_wrapper.has_value())
return 1;
diff --git a/Services/WebServer/Client.cpp b/Services/WebServer/Client.cpp
index 6e8f10dba4..deb582e013 100644
--- a/Services/WebServer/Client.cpp
+++ b/Services/WebServer/Client.cpp
@@ -65,12 +65,12 @@ void Client::start()
dbg() << "Got raw request: '" << String::copy(raw_request) << "'";
- handle_request(move(raw_request));
+ handle_request(raw_request.bytes());
die();
};
}
-void Client::handle_request(ByteBuffer raw_request)
+void Client::handle_request(ReadonlyBytes raw_request)
{
auto request_or_error = HTTP::HttpRequest::from_raw_request(raw_request);
if (!request_or_error.has_value())
diff --git a/Services/WebServer/Client.h b/Services/WebServer/Client.h
index 6b078bb568..f363c9d9eb 100644
--- a/Services/WebServer/Client.h
+++ b/Services/WebServer/Client.h
@@ -41,7 +41,7 @@ public:
private:
Client(NonnullRefPtr<Core::TCPSocket>, const String&, Core::Object* parent);
- void handle_request(ByteBuffer);
+ void handle_request(ReadonlyBytes);
void send_response(StringView, const HTTP::HttpRequest&, const String& content_type);
void send_redirect(StringView redirect, const HTTP::HttpRequest& request);
void send_error_response(unsigned code, const StringView& message, const HTTP::HttpRequest&);