90 lines
1.6 KiB
C++
90 lines
1.6 KiB
C++
#include "client.h"
|
|
|
|
|
|
|
|
|
|
Client::Client()
|
|
{
|
|
in_buffer_max_len = WEBSERVER_INPUT_BUFFER_MAX_LEN;
|
|
socket = 0;
|
|
in_buffer = nullptr;
|
|
in_buffer_len = 0;
|
|
parsing_headers = true;
|
|
parsing_first_header = true;
|
|
http_method = http_method_unsupported;
|
|
http_version = http_version_unsupported;
|
|
answer_generated = false;
|
|
output_buffer_sent = 0;
|
|
close_connection = false;
|
|
}
|
|
|
|
|
|
Client::Client(const Client & c)
|
|
{
|
|
in_buffer = nullptr;
|
|
operator=(c);
|
|
}
|
|
|
|
|
|
Client::~Client()
|
|
{
|
|
delete [] in_buffer;
|
|
}
|
|
|
|
|
|
Client & Client::operator=(const Client & c)
|
|
{
|
|
socket = c.socket;
|
|
|
|
if( c.in_buffer )
|
|
AllocInputBuffer();
|
|
else
|
|
in_buffer = nullptr;
|
|
|
|
in_buffer_len = c.in_buffer_len;
|
|
in_buffer_max_len = c.in_buffer_max_len;
|
|
parsing_headers = c.parsing_headers;
|
|
parsing_first_header = c.parsing_first_header;
|
|
http_method_str = c.http_method_str;
|
|
http_method = c.http_method;
|
|
http_version = c.http_version;
|
|
url = c.url;
|
|
answer_generated = c.answer_generated;
|
|
|
|
output_buffer = c.output_buffer;
|
|
output_buffer_sent = c.output_buffer_sent;
|
|
close_connection = c.close_connection;
|
|
|
|
return *this;
|
|
}
|
|
|
|
|
|
|
|
|
|
void Client::AllocInputBuffer()
|
|
{
|
|
delete [] in_buffer;
|
|
in_buffer = new char[in_buffer_max_len];
|
|
}
|
|
|
|
|
|
void Client::PrepareToNewRequest()
|
|
{
|
|
if( !in_buffer )
|
|
AllocInputBuffer();
|
|
|
|
parsing_headers = true;
|
|
parsing_first_header = true;
|
|
in_buffer_len = 0;
|
|
http_method = http_method_unsupported;
|
|
http_version = http_version_unsupported;
|
|
answer_generated = false;
|
|
output_buffer_sent = 0;
|
|
|
|
http_method_str.clear();
|
|
output_buffer.clear();
|
|
url.clear();
|
|
|
|
// don't set flag close_connection to false here
|
|
}
|