diff options
author | Linus Groh <mail@linusgroh.de> | 2023-03-09 14:51:20 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-03-09 14:51:20 +0000 |
commit | d0ecd818889da9bee9096967e9e37fd813a6f9b1 (patch) | |
tree | 773fe00ab2d8a427dcae04c9b2ee4cd6ef0908ec /Userland/Libraries/LibHTTP | |
parent | f068ddb79fad03c8afef3e5119509fc624dcadd7 (diff) | |
download | serenity-d0ecd818889da9bee9096967e9e37fd813a6f9b1.zip |
LibHTTP: Propagate OOM errors from HttpRequest::to_raw_request()
Diffstat (limited to 'Userland/Libraries/LibHTTP')
-rw-r--r-- | Userland/Libraries/LibHTTP/HttpRequest.cpp | 36 | ||||
-rw-r--r-- | Userland/Libraries/LibHTTP/HttpRequest.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibHTTP/Job.cpp | 2 |
3 files changed, 20 insertions, 20 deletions
diff --git a/Userland/Libraries/LibHTTP/HttpRequest.cpp b/Userland/Libraries/LibHTTP/HttpRequest.cpp index 9ac9255e9f..0a33e227ab 100644 --- a/Userland/Libraries/LibHTTP/HttpRequest.cpp +++ b/Userland/Libraries/LibHTTP/HttpRequest.cpp @@ -43,36 +43,36 @@ DeprecatedString HttpRequest::method_name() const return to_deprecated_string(m_method); } -ByteBuffer HttpRequest::to_raw_request() const +ErrorOr<ByteBuffer> HttpRequest::to_raw_request() const { StringBuilder builder; - builder.append(method_name()); - builder.append(' '); + TRY(builder.try_append(method_name())); + TRY(builder.try_append(' ')); // NOTE: The percent_encode is so that e.g. spaces are properly encoded. auto path = m_url.path(); VERIFY(!path.is_empty()); - builder.append(URL::percent_encode(m_url.path(), URL::PercentEncodeSet::EncodeURI)); + TRY(builder.try_append(URL::percent_encode(m_url.path(), URL::PercentEncodeSet::EncodeURI))); if (!m_url.query().is_empty()) { - builder.append('?'); - builder.append(m_url.query()); + TRY(builder.try_append('?')); + TRY(builder.try_append(m_url.query())); } - builder.append(" HTTP/1.1\r\nHost: "sv); - builder.append(m_url.host()); + TRY(builder.try_append(" HTTP/1.1\r\nHost: "sv)); + TRY(builder.try_append(m_url.host())); if (m_url.port().has_value()) - builder.appendff(":{}", *m_url.port()); - builder.append("\r\n"sv); + TRY(builder.try_appendff(":{}", *m_url.port())); + TRY(builder.try_append("\r\n"sv)); for (auto& header : m_headers) { - builder.append(header.name); - builder.append(": "sv); - builder.append(header.value); - builder.append("\r\n"sv); + TRY(builder.try_append(header.name)); + TRY(builder.try_append(": "sv)); + TRY(builder.try_append(header.value)); + TRY(builder.try_append("\r\n"sv)); } if (!m_body.is_empty() || method() == Method::POST) { - builder.appendff("Content-Length: {}\r\n\r\n", m_body.size()); - builder.append((char const*)m_body.data(), m_body.size()); + TRY(builder.try_appendff("Content-Length: {}\r\n\r\n", m_body.size())); + TRY(builder.try_append((char const*)m_body.data(), m_body.size())); } - builder.append("\r\n"sv); - return builder.to_byte_buffer(); + TRY(builder.try_append("\r\n"sv)); + return builder.try_to_byte_buffer(); } Optional<HttpRequest> HttpRequest::from_raw_request(ReadonlyBytes raw_request) diff --git a/Userland/Libraries/LibHTTP/HttpRequest.h b/Userland/Libraries/LibHTTP/HttpRequest.h index 7ab76f6c77..effa66b852 100644 --- a/Userland/Libraries/LibHTTP/HttpRequest.h +++ b/Userland/Libraries/LibHTTP/HttpRequest.h @@ -57,7 +57,7 @@ public: void set_body(ByteBuffer&& body) { m_body = move(body); } DeprecatedString method_name() const; - ByteBuffer to_raw_request() const; + ErrorOr<ByteBuffer> to_raw_request() const; void set_headers(HashMap<DeprecatedString, DeprecatedString> const&); diff --git a/Userland/Libraries/LibHTTP/Job.cpp b/Userland/Libraries/LibHTTP/Job.cpp index d5eeae2434..8bacd97d39 100644 --- a/Userland/Libraries/LibHTTP/Job.cpp +++ b/Userland/Libraries/LibHTTP/Job.cpp @@ -195,7 +195,7 @@ ErrorOr<ByteBuffer> Job::receive(size_t size) void Job::on_socket_connected() { - auto raw_request = m_request.to_raw_request(); + auto raw_request = m_request.to_raw_request().release_value_but_fixme_should_propagate_errors(); if constexpr (JOB_DEBUG) { dbgln("Job: raw_request:"); |