171 lines
2.2 KiB
C++
171 lines
2.2 KiB
C++
#ifndef headerfile_libscorpiohttpserver_src_client_h
|
|
#define headerfile_libscorpiohttpserver_src_client_h
|
|
|
|
|
|
#include <aio.h>
|
|
#include <space/space.h>
|
|
|
|
|
|
#define WEBSERVER_INPUT_BUFFER_MAX_LEN 8196
|
|
|
|
|
|
|
|
enum HTTPMethod
|
|
{
|
|
http_method_get = 0,
|
|
http_method_post,
|
|
http_method_put,
|
|
http_method_delete,
|
|
http_method_options,
|
|
http_method_unsupported
|
|
};
|
|
|
|
|
|
enum HTTPVersion
|
|
{
|
|
http_version_1_0,
|
|
http_version_1_1,
|
|
http_version_unsupported
|
|
};
|
|
|
|
|
|
struct ExternalResource
|
|
{
|
|
enum Type
|
|
{
|
|
type_file,
|
|
type_none,
|
|
|
|
};
|
|
|
|
|
|
ExternalResource()
|
|
{
|
|
Clear();
|
|
}
|
|
|
|
void Clear()
|
|
{
|
|
type = type_none;
|
|
reading_external_resource = false;
|
|
external_resource_fd = -1;
|
|
file_len = 0;
|
|
waiting_for_last_read = false;
|
|
file_how_many_read = 0;
|
|
}
|
|
|
|
Type type;
|
|
|
|
/*
|
|
* reading an external resource such as a file
|
|
*
|
|
*/
|
|
bool reading_external_resource;
|
|
|
|
int external_resource_fd;
|
|
|
|
size_t file_len;
|
|
bool waiting_for_last_read;
|
|
size_t file_how_many_read;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Client
|
|
{
|
|
public:
|
|
|
|
|
|
|
|
int socket;
|
|
PT::Space in;
|
|
|
|
std::wstring url;
|
|
HTTPMethod http_method;
|
|
HTTPVersion http_version;
|
|
|
|
|
|
// a better name?
|
|
PT::Space out_headers;
|
|
|
|
|
|
|
|
|
|
int status;
|
|
|
|
|
|
|
|
|
|
|
|
bool answer_generated;
|
|
|
|
bool close_connection;
|
|
|
|
std::string input_buffer;
|
|
std::string header;
|
|
|
|
bool parsing_headers;
|
|
bool parsing_first_header;
|
|
|
|
|
|
|
|
std::wstring send_file;
|
|
|
|
//size_t how_many_to_send;
|
|
|
|
|
|
ExternalResource external_resource;
|
|
|
|
std::string output_buffer;
|
|
std::string output_buffer_two;
|
|
|
|
size_t output_buffer_sent; // how many characters were sent
|
|
size_t output_buffer_two_sent; // how many characters were sent
|
|
|
|
int reading_to_buffer;
|
|
int sending_from_buffer;
|
|
|
|
|
|
bool reading_to_buffer_two;
|
|
bool sending_from_buffer_two;
|
|
|
|
/*
|
|
* if true then all headers has been read and now the server
|
|
* is creating the response
|
|
*
|
|
*/
|
|
bool answering_to_client;
|
|
|
|
char * read_static_buffer;
|
|
size_t read_static_buffer_size;
|
|
|
|
|
|
aiocb iocb;
|
|
|
|
Client();
|
|
Client(const Client & c);
|
|
~Client();
|
|
|
|
Client & operator=(const Client & c);
|
|
|
|
void PrepareToNewRequest();
|
|
|
|
|
|
private:
|
|
|
|
//char * in_buffer; // rename to a better name
|
|
//size_t in_buffer_max_len; // at least two characters
|
|
//size_t in_buffer_len;
|
|
std::wstring http_method_str;
|
|
|
|
|
|
friend class Server;
|
|
friend class HeadersParser;
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|