summaryrefslogtreecommitdiff
path: root/Libraries/LibHTTP
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-06-12 21:07:52 +0200
committerAndreas Kling <kling@serenityos.org>2020-06-12 21:28:55 +0200
commitfdfda6dec20101013bb33633e657f06ef2a1ea96 (patch)
tree2157f8281cd9bc33a6984455c4831c397d2bd30c /Libraries/LibHTTP
parent15f4043a7a80f52c0fa05c4e69771e758464cd20 (diff)
downloadserenity-fdfda6dec20101013bb33633e657f06ef2a1ea96.zip
AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature: - int StringType::to_int(bool& ok) const And replace it with sensible new signature: - Optional<int> StringType::to_int() const
Diffstat (limited to 'Libraries/LibHTTP')
-rw-r--r--Libraries/LibHTTP/Job.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/Libraries/LibHTTP/Job.cpp b/Libraries/LibHTTP/Job.cpp
index 64ad05f010..c1d5e8bae6 100644
--- a/Libraries/LibHTTP/Job.cpp
+++ b/Libraries/LibHTTP/Job.cpp
@@ -108,12 +108,12 @@ void Job::on_socket_connected()
fprintf(stderr, "Job: Expected 3-part HTTP status, got '%s'\n", line.data());
return deferred_invoke([this](auto&) { did_fail(Core::NetworkJob::Error::ProtocolFailed); });
}
- bool ok;
- m_code = parts[1].to_uint(ok);
- if (!ok) {
+ auto code = parts[1].to_uint();
+ if (!code.has_value()) {
fprintf(stderr, "Job: Expected numeric HTTP status\n");
return deferred_invoke([this](auto&) { did_fail(Core::NetworkJob::Error::ProtocolFailed); });
}
+ m_code = code.value();
m_state = State::InHeaders;
return;
}
@@ -266,10 +266,9 @@ void Job::on_socket_connected()
Optional<u32> content_length {};
if (content_length_header.has_value()) {
- bool ok;
- auto length = content_length_header.value().to_uint(ok);
- if (ok)
- content_length = length;
+ auto length = content_length_header.value().to_uint();
+ if (length.has_value())
+ content_length = length.value();
}
deferred_invoke([this, content_length](auto&) { did_progress(content_length, m_received_size); });