1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:58:11 +00:00
serenity/Libraries/LibCore/CHttpJob.h
Andreas Kling 4298ba25c3 LibCore: Convert CTCPSocket to ObjectPtr, add construct() helper
The C_OBJECT macro now also inserts a static construct(...) helper into
the class. Now we can make the constructor(s) private and instead call:

    auto socket = CTCPSocket::construct(arguments);

construct() returns an ObjectPtr<T>, which we'll later switch to being
a NonnullRefPtr<T>, once everything else in in place for ref-counting.
2019-09-21 15:25:08 +02:00

35 lines
726 B
C++

#pragma once
#include <AK/HashMap.h>
#include <LibCore/CHttpRequest.h>
#include <LibCore/CNetworkJob.h>
class CTCPSocket;
class CHttpJob final : public CNetworkJob {
C_OBJECT(CHttpJob)
public:
explicit CHttpJob(const CHttpRequest&);
virtual ~CHttpJob() override;
virtual void start() override;
private:
void on_socket_connected();
void finish_up();
enum class State {
InStatus,
InHeaders,
InBody,
Finished,
};
CHttpRequest m_request;
ObjectPtr<CTCPSocket> 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 };
};