2019-04-07 14:36:10 +02:00
|
|
|
#include <AK/StringBuilder.h>
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <LibCore/CHttpJob.h>
|
|
|
|
#include <LibCore/CHttpRequest.h>
|
2019-04-07 14:36:10 +02:00
|
|
|
|
2019-04-10 22:28:10 +02:00
|
|
|
CHttpRequest::CHttpRequest()
|
2019-04-07 14:36:10 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-04-10 22:28:10 +02:00
|
|
|
CHttpRequest::~CHttpRequest()
|
2019-04-07 14:36:10 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-09-22 00:31:54 +02:00
|
|
|
RefPtr<CNetworkJob> CHttpRequest::schedule()
|
2019-04-07 14:36:10 +02:00
|
|
|
{
|
2019-09-21 12:03:22 +02:00
|
|
|
auto job = CHttpJob::construct(*this);
|
2019-04-07 14:36:10 +02:00
|
|
|
job->start();
|
|
|
|
return job;
|
|
|
|
}
|
|
|
|
|
2019-04-10 22:28:10 +02:00
|
|
|
String CHttpRequest::method_name() const
|
2019-04-07 14:36:10 +02:00
|
|
|
{
|
|
|
|
switch (m_method) {
|
|
|
|
case Method::GET:
|
|
|
|
return "GET";
|
|
|
|
case Method::HEAD:
|
|
|
|
return "HEAD";
|
|
|
|
case Method::POST:
|
|
|
|
return "POST";
|
|
|
|
default:
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-10 22:28:10 +02:00
|
|
|
ByteBuffer CHttpRequest::to_raw_request() const
|
2019-04-07 14:36:10 +02:00
|
|
|
{
|
|
|
|
StringBuilder builder;
|
|
|
|
builder.append(method_name());
|
|
|
|
builder.append(' ');
|
2019-08-10 19:32:03 +02:00
|
|
|
builder.append(m_url.path());
|
2019-06-22 23:04:31 +02:00
|
|
|
builder.append(" HTTP/1.0\r\nHost: ");
|
2019-08-10 19:32:03 +02:00
|
|
|
builder.append(m_url.host());
|
2019-06-22 22:10:43 +02:00
|
|
|
builder.append("\r\n\r\n");
|
2019-04-07 14:36:10 +02:00
|
|
|
return builder.to_byte_buffer();
|
|
|
|
}
|