mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 01:55:00 +00:00

Now there's just CHttpRequest::set_url(URL), no need to specify the host, port and path manually anymore. Updated ChanViewer and Downloader for the API change.
44 lines
852 B
C++
44 lines
852 B
C++
#include <AK/StringBuilder.h>
|
|
#include <LibCore/CHttpJob.h>
|
|
#include <LibCore/CHttpRequest.h>
|
|
|
|
CHttpRequest::CHttpRequest()
|
|
{
|
|
}
|
|
|
|
CHttpRequest::~CHttpRequest()
|
|
{
|
|
}
|
|
|
|
CNetworkJob* CHttpRequest::schedule()
|
|
{
|
|
auto* job = new CHttpJob(*this);
|
|
job->start();
|
|
return job;
|
|
}
|
|
|
|
String CHttpRequest::method_name() const
|
|
{
|
|
switch (m_method) {
|
|
case Method::GET:
|
|
return "GET";
|
|
case Method::HEAD:
|
|
return "HEAD";
|
|
case Method::POST:
|
|
return "POST";
|
|
default:
|
|
ASSERT_NOT_REACHED();
|
|
}
|
|
}
|
|
|
|
ByteBuffer CHttpRequest::to_raw_request() const
|
|
{
|
|
StringBuilder builder;
|
|
builder.append(method_name());
|
|
builder.append(' ');
|
|
builder.append(m_url.path());
|
|
builder.append(" HTTP/1.0\r\nHost: ");
|
|
builder.append(m_url.host());
|
|
builder.append("\r\n\r\n");
|
|
return builder.to_byte_buffer();
|
|
}
|