mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:37:35 +00:00
GHttp: Rename GHttpNetworkJob => GHttpJob. And tidy up a little bit.
This commit is contained in:
parent
37ae00a4dd
commit
7fcca0ce4b
4 changed files with 15 additions and 16 deletions
|
@ -1,19 +1,19 @@
|
||||||
#include <LibGUI/GHttpNetworkJob.h>
|
#include <LibGUI/GHttpJob.h>
|
||||||
#include <LibGUI/GHttpResponse.h>
|
#include <LibGUI/GHttpResponse.h>
|
||||||
#include <LibGUI/GTCPSocket.h>
|
#include <LibGUI/GTCPSocket.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
GHttpNetworkJob::GHttpNetworkJob(const GHttpRequest& request)
|
GHttpJob::GHttpJob(const GHttpRequest& request)
|
||||||
: m_request(request)
|
: m_request(request)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GHttpNetworkJob::~GHttpNetworkJob()
|
GHttpJob::~GHttpJob()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GHttpNetworkJob::start()
|
void GHttpJob::start()
|
||||||
{
|
{
|
||||||
ASSERT(!m_socket);
|
ASSERT(!m_socket);
|
||||||
m_socket = new GTCPSocket(this);
|
m_socket = new GTCPSocket(this);
|
||||||
|
@ -35,7 +35,7 @@ void GHttpNetworkJob::start()
|
||||||
while (!m_socket->can_read_line())
|
while (!m_socket->can_read_line())
|
||||||
usleep(1);
|
usleep(1);
|
||||||
ASSERT(m_socket->can_read_line());
|
ASSERT(m_socket->can_read_line());
|
||||||
auto line = m_socket->read_line(1024);
|
auto line = m_socket->read_line(PAGE_SIZE);
|
||||||
if (line.is_null()) {
|
if (line.is_null()) {
|
||||||
printf("Expected HTTP status\n");
|
printf("Expected HTTP status\n");
|
||||||
return deferred_invoke([this](auto&){ did_fail(GNetworkJob::Error::TransmissionFailed); });
|
return deferred_invoke([this](auto&){ did_fail(GNetworkJob::Error::TransmissionFailed); });
|
||||||
|
@ -57,7 +57,7 @@ void GHttpNetworkJob::start()
|
||||||
if (m_state == State::InHeaders) {
|
if (m_state == State::InHeaders) {
|
||||||
while (!m_socket->can_read_line())
|
while (!m_socket->can_read_line())
|
||||||
usleep(1);
|
usleep(1);
|
||||||
auto line = m_socket->read_line(1024);
|
auto line = m_socket->read_line(PAGE_SIZE);
|
||||||
if (line.is_null()) {
|
if (line.is_null()) {
|
||||||
printf("Expected HTTP header\n");
|
printf("Expected HTTP header\n");
|
||||||
return did_fail(GNetworkJob::Error::ProtocolFailed);
|
return did_fail(GNetworkJob::Error::ProtocolFailed);
|
||||||
|
@ -83,7 +83,7 @@ void GHttpNetworkJob::start()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ASSERT(m_state == State::InBody);
|
ASSERT(m_state == State::InBody);
|
||||||
auto payload = m_socket->receive(100000);
|
auto payload = m_socket->receive(PAGE_SIZE);
|
||||||
if (!payload) {
|
if (!payload) {
|
||||||
if (m_socket->eof()) {
|
if (m_socket->eof()) {
|
||||||
m_state = State::Finished;
|
m_state = State::Finished;
|
||||||
|
@ -95,8 +95,7 @@ void GHttpNetworkJob::start()
|
||||||
}
|
}
|
||||||
|
|
||||||
auto response = GHttpResponse::create(m_code, move(m_headers), ByteBuffer::copy(buffer.data(), buffer.size()));
|
auto response = GHttpResponse::create(m_code, move(m_headers), ByteBuffer::copy(buffer.data(), buffer.size()));
|
||||||
deferred_invoke([this, response] (GObject&) {
|
deferred_invoke([this, response] (auto&) {
|
||||||
printf("in the deferred invoke lambda\n");
|
|
||||||
did_finish(move(response));
|
did_finish(move(response));
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -6,14 +6,14 @@
|
||||||
|
|
||||||
class GTCPSocket;
|
class GTCPSocket;
|
||||||
|
|
||||||
class GHttpNetworkJob final : public GNetworkJob {
|
class GHttpJob final : public GNetworkJob {
|
||||||
public:
|
public:
|
||||||
explicit GHttpNetworkJob(const GHttpRequest&);
|
explicit GHttpJob(const GHttpRequest&);
|
||||||
virtual ~GHttpNetworkJob() override;
|
virtual ~GHttpJob() override;
|
||||||
|
|
||||||
virtual void start() override;
|
virtual void start() override;
|
||||||
|
|
||||||
virtual const char* class_name() const override { return "GHttpNetworkJob"; }
|
virtual const char* class_name() const override { return "GHttpJob"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class State {
|
enum class State {
|
|
@ -1,5 +1,5 @@
|
||||||
#include <LibGUI/GHttpRequest.h>
|
#include <LibGUI/GHttpRequest.h>
|
||||||
#include <LibGUI/GHttpNetworkJob.h>
|
#include <LibGUI/GHttpJob.h>
|
||||||
#include <LibGUI/GEventLoop.h>
|
#include <LibGUI/GEventLoop.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ GHttpRequest::~GHttpRequest()
|
||||||
|
|
||||||
GNetworkJob* GHttpRequest::schedule()
|
GNetworkJob* GHttpRequest::schedule()
|
||||||
{
|
{
|
||||||
auto* job = new GHttpNetworkJob(*this);
|
auto* job = new GHttpJob(*this);
|
||||||
job->start();
|
job->start();
|
||||||
return job;
|
return job;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ LIBGUI_OBJS = \
|
||||||
GNetworkResponse.o \
|
GNetworkResponse.o \
|
||||||
GHttpRequest.o \
|
GHttpRequest.o \
|
||||||
GHttpResponse.o \
|
GHttpResponse.o \
|
||||||
GHttpNetworkJob.o \
|
GHttpJob.o \
|
||||||
GWindow.o
|
GWindow.o
|
||||||
|
|
||||||
OBJS = $(SHAREDGRAPHICS_OBJS) $(LIBGUI_OBJS)
|
OBJS = $(SHAREDGRAPHICS_OBJS) $(LIBGUI_OBJS)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue