2019-04-07 14:36:10 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-04-07 19:35:07 +02:00
|
|
|
#include <AK/HashMap.h>
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <LibCore/CHttpRequest.h>
|
2019-12-10 20:46:33 +01:00
|
|
|
#include <LibCore/CHttpResponse.h>
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <LibCore/CNetworkJob.h>
|
2019-04-07 14:36:10 +02:00
|
|
|
|
2019-04-10 20:22:23 +02:00
|
|
|
class CTCPSocket;
|
2019-04-07 14:36:10 +02:00
|
|
|
|
2019-04-10 22:28:10 +02:00
|
|
|
class CHttpJob final : public CNetworkJob {
|
2019-07-25 19:49:28 +02:00
|
|
|
C_OBJECT(CHttpJob)
|
2019-04-07 14:36:10 +02:00
|
|
|
public:
|
2019-04-10 22:28:10 +02:00
|
|
|
explicit CHttpJob(const CHttpRequest&);
|
|
|
|
|
virtual ~CHttpJob() override;
|
2019-04-07 14:36:10 +02:00
|
|
|
|
|
|
|
|
virtual void start() override;
|
2019-09-21 17:32:26 +02:00
|
|
|
virtual void shutdown() override;
|
2019-04-07 14:36:10 +02:00
|
|
|
|
2019-12-10 20:46:33 +01:00
|
|
|
CHttpResponse* response() { return static_cast<CHttpResponse*>(CNetworkJob::response()); }
|
|
|
|
|
const CHttpResponse* response() const { return static_cast<const CHttpResponse*>(CNetworkJob::response()); }
|
|
|
|
|
|
2019-04-07 14:36:10 +02:00
|
|
|
private:
|
2019-04-08 04:53:45 +02:00
|
|
|
void on_socket_connected();
|
2019-08-04 18:55:52 +02:00
|
|
|
void finish_up();
|
2019-04-08 04:53:45 +02:00
|
|
|
|
2019-06-07 17:13:23 +02:00
|
|
|
enum class State {
|
2019-04-07 19:35:07 +02:00
|
|
|
InStatus,
|
|
|
|
|
InHeaders,
|
|
|
|
|
InBody,
|
|
|
|
|
Finished,
|
|
|
|
|
};
|
|
|
|
|
|
2019-04-10 22:28:10 +02:00
|
|
|
CHttpRequest m_request;
|
2019-09-22 00:31:54 +02:00
|
|
|
RefPtr<CTCPSocket> m_socket;
|
2019-04-07 19:35:07 +02:00
|
|
|
State m_state { State::InStatus };
|
|
|
|
|
int m_code { -1 };
|
|
|
|
|
HashMap<String, String> m_headers;
|
2019-08-04 18:55:52 +02:00
|
|
|
Vector<ByteBuffer> m_received_buffers;
|
|
|
|
|
size_t m_received_size { 0 };
|
2019-04-07 14:36:10 +02:00
|
|
|
};
|