summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorArda Cinar <kuzux92@gmail.com>2023-01-13 19:55:20 +0300
committerAndreas Kling <kling@serenityos.org>2023-01-14 12:28:02 +0100
commit0245a62f81f7d596838e80b3f342eae2deefcb17 (patch)
treeb510ebd5c5fb80e97e4b28360494f942042e741d /Userland/Libraries
parent5b45b26613ac24e38ba7de15b70eeb9e753c0cc0 (diff)
downloadserenity-0245a62f81f7d596838e80b3f342eae2deefcb17.zip
LibGemini: Add a response length helper to Gemini::Job
Unlike HTTP responses, Gemini responses do not have a length header or a delimiter for the end of a response. A response simply continues until the connection is closed and its length is the number of bytes received. So, the response length method only returns the result if it has finished
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGemini/Job.cpp9
-rw-r--r--Userland/Libraries/LibGemini/Job.h2
2 files changed, 11 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGemini/Job.cpp b/Userland/Libraries/LibGemini/Job.cpp
index 099b358a74..43412e1363 100644
--- a/Userland/Libraries/LibGemini/Job.cpp
+++ b/Userland/Libraries/LibGemini/Job.cpp
@@ -5,6 +5,7 @@
*/
#include <AK/Debug.h>
+#include <AK/Error.h>
#include <LibCore/Stream.h>
#include <LibGemini/GeminiResponse.h>
#include <LibGemini/Job.h>
@@ -223,4 +224,12 @@ void Job::finish_up()
did_finish(move(response));
});
}
+
+ErrorOr<size_t> Job::response_length() const
+{
+ if (m_state != State::Finished)
+ return AK::Error::from_string_literal("Gemini response has not finished");
+
+ return m_received_size;
+}
}
diff --git a/Userland/Libraries/LibGemini/Job.h b/Userland/Libraries/LibGemini/Job.h
index c4df2ec504..afa883721b 100644
--- a/Userland/Libraries/LibGemini/Job.h
+++ b/Userland/Libraries/LibGemini/Job.h
@@ -29,6 +29,8 @@ public:
const URL& url() const { return m_request.url(); }
Core::Stream::Socket const* socket() const { return m_socket; }
+ ErrorOr<size_t> response_length() const;
+
protected:
void finish_up();
void on_socket_connected();