1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 12:15:07 +00:00

LibCore: Move CHttpJob and CNetworkJob output to the right places

Errors go to stderr, debug output goes to the debug console. :^)
This commit is contained in:
Andreas Kling 2019-08-04 22:10:54 +02:00
parent 948c2657d6
commit 54ed6a888d
2 changed files with 11 additions and 10 deletions

View file

@ -17,7 +17,8 @@ void CHttpJob::on_socket_connected()
{ {
auto raw_request = m_request.to_raw_request(); auto raw_request = m_request.to_raw_request();
#if 0 #if 0
printf("raw_request:\n%s\n", String::copy(raw_request).characters()); dbg() << "CHttpJob: raw_request:";
dbg() << String::copy(raw_request).characters();
#endif #endif
bool success = m_socket->send(raw_request); bool success = m_socket->send(raw_request);
@ -30,18 +31,18 @@ void CHttpJob::on_socket_connected()
return; return;
auto line = m_socket->read_line(PAGE_SIZE); auto line = m_socket->read_line(PAGE_SIZE);
if (line.is_null()) { if (line.is_null()) {
printf("Expected HTTP status\n"); fprintf(stderr, "CHttpJob: Expected HTTP status\n");
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::TransmissionFailed); }); return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::TransmissionFailed); });
} }
auto parts = String::copy(line, Chomp).split(' '); auto parts = String::copy(line, Chomp).split(' ');
if (parts.size() < 3) { if (parts.size() < 3) {
printf("Expected 3-part HTTP status, got '%s'\n", line.pointer()); fprintf(stderr, "CHttpJob: Expected 3-part HTTP status, got '%s'\n", line.pointer());
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); }); return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
} }
bool ok; bool ok;
m_code = parts[1].to_uint(ok); m_code = parts[1].to_uint(ok);
if (!ok) { if (!ok) {
printf("Expected numeric HTTP status\n"); fprintf(stderr, "CHttpJob: Expected numeric HTTP status\n");
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); }); return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
} }
m_state = State::InHeaders; m_state = State::InHeaders;
@ -52,7 +53,7 @@ void CHttpJob::on_socket_connected()
return; return;
auto line = m_socket->read_line(PAGE_SIZE); auto line = m_socket->read_line(PAGE_SIZE);
if (line.is_null()) { if (line.is_null()) {
printf("Expected HTTP header\n"); fprintf(stderr, "CHttpJob: Expected HTTP header\n");
return did_fail(CNetworkJob::Error::ProtocolFailed); return did_fail(CNetworkJob::Error::ProtocolFailed);
} }
auto chomped_line = String::copy(line, Chomp); auto chomped_line = String::copy(line, Chomp);
@ -62,17 +63,17 @@ void CHttpJob::on_socket_connected()
} }
auto parts = chomped_line.split(':'); auto parts = chomped_line.split(':');
if (parts.is_empty()) { if (parts.is_empty()) {
printf("Expected HTTP header with key/value\n"); fprintf(stderr, "CHttpJob: Expected HTTP header with key/value\n");
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); }); return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
} }
auto name = parts[0]; auto name = parts[0];
if (chomped_line.length() < name.length() + 2) { if (chomped_line.length() < name.length() + 2) {
printf("Malformed HTTP header: '%s' (%d)\n", chomped_line.characters(), chomped_line.length()); fprintf(stderr, "CHttpJob: Malformed HTTP header: '%s' (%d)\n", chomped_line.characters(), chomped_line.length());
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); }); return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
} }
auto value = chomped_line.substring(name.length() + 2, chomped_line.length() - name.length() - 2); auto value = chomped_line.substring(name.length() + 2, chomped_line.length() - name.length() - 2);
m_headers.set(name, value); m_headers.set(name, value);
printf("[%s] = '%s'\n", name.characters(), value.characters()); dbg() << "CHttpJob: [" << name << "] = '" << value << "'";
return; return;
} }
ASSERT(m_state == State::InBody); ASSERT(m_state == State::InBody);
@ -117,7 +118,7 @@ void CHttpJob::start()
ASSERT(!m_socket); ASSERT(!m_socket);
m_socket = new CTCPSocket(this); m_socket = new CTCPSocket(this);
m_socket->on_connected = [this] { m_socket->on_connected = [this] {
printf("Socket on_connected callback\n"); dbg() << "CHttpJob: on_connected callback";
on_socket_connected(); on_socket_connected();
}; };
bool success = m_socket->connect(m_request.hostname(), m_request.port()); bool success = m_socket->connect(m_request.hostname(), m_request.port());

View file

@ -13,7 +13,7 @@ CNetworkJob::~CNetworkJob()
void CNetworkJob::did_finish(NonnullRefPtr<CNetworkResponse>&& response) void CNetworkJob::did_finish(NonnullRefPtr<CNetworkResponse>&& response)
{ {
m_response = move(response); m_response = move(response);
printf("%s{%p} job did_finish!\n", class_name(), this); dbg() << *this << " job did_finish!";
ASSERT(on_finish); ASSERT(on_finish);
on_finish(true); on_finish(true);
delete_later(); delete_later();