summaryrefslogtreecommitdiff
path: root/Libraries/LibHTTP/HttpsJob.h
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-05-05 09:47:40 +0430
committerAndreas Kling <kling@serenityos.org>2020-05-05 11:04:06 +0200
commit155853afb24bd631395f81a641da4cc23ce6aef9 (patch)
tree2cacf99e2076f8b11b7a25e489cb8ecf9b17fa97 /Libraries/LibHTTP/HttpsJob.h
parent3dd0f755d05c807649eb86bd8e0472ce77661b41 (diff)
downloadserenity-155853afb24bd631395f81a641da4cc23ce6aef9.zip
LibHTTP: Unify and generalise response handling logic
Diffstat (limited to 'Libraries/LibHTTP/HttpsJob.h')
-rw-r--r--Libraries/LibHTTP/HttpsJob.h46
1 files changed, 22 insertions, 24 deletions
diff --git a/Libraries/LibHTTP/HttpsJob.h b/Libraries/LibHTTP/HttpsJob.h
index 6b5019c824..f426c9803e 100644
--- a/Libraries/LibHTTP/HttpsJob.h
+++ b/Libraries/LibHTTP/HttpsJob.h
@@ -30,43 +30,41 @@
#include <LibCore/NetworkJob.h>
#include <LibHTTP/HttpRequest.h>
#include <LibHTTP/HttpResponse.h>
+#include <LibHTTP/Job.h>
#include <LibTLS/TLSv12.h>
namespace HTTP {
-class HttpsJob final : public Core::NetworkJob {
+class HttpsJob final : public Job {
C_OBJECT(HttpsJob)
public:
- explicit HttpsJob(const HttpRequest&);
- virtual ~HttpsJob() override;
+ explicit HttpsJob(const HttpRequest& request)
+ : Job(request)
+ {
+ }
+
+ virtual ~HttpsJob() override
+ {
+ }
virtual void start() override;
virtual void shutdown() override;
- HttpResponse* response() { return static_cast<HttpResponse*>(Core::NetworkJob::response()); }
- const HttpResponse* response() const { return static_cast<const HttpResponse*>(Core::NetworkJob::response()); }
+protected:
+ virtual void register_on_ready_to_read(Function<void()>) override;
+ virtual void register_on_ready_to_write(Function<void()>) override;
+ virtual bool can_read_line() override;
+ virtual ByteBuffer read_line(size_t) override;
+ virtual bool can_read() const override;
+ virtual ByteBuffer receive(size_t) override;
+ virtual bool eof() const override;
+ virtual bool write(const ByteBuffer&) override;
+ virtual bool is_established() const override { return m_socket->is_established(); }
+ virtual bool should_fail_on_empty_payload() const override { return false; }
+ virtual void read_while_data_available(Function<IterationDecision()>) override;
private:
- RefPtr<TLS::TLSv12> construct_socket() { return TLS::TLSv12::construct(this); }
- void on_socket_connected();
- void finish_up();
- void read_body(TLS::TLSv12&);
-
- enum class State {
- InStatus,
- InHeaders,
- InBody,
- Finished,
- };
-
- HttpRequest m_request;
RefPtr<TLS::TLSv12> m_socket;
- State m_state { State::InStatus };
- int m_code { -1 };
- HashMap<String, String> m_headers;
- Vector<ByteBuffer> m_received_buffers;
- size_t m_received_size { 0 };
- bool m_sent_data { false };
bool m_queued_finish { false };
};