18 bool Read(std::string & strbuf);
20 std::string
GetVar(std::string i);
22 void SetHeader(std::string i, std::string v);
23 void SetHeader(std::string i,
long long v);
25 void SetVar(std::string i, std::string v);
27 void SetBody(
const char * buffer,
int len);
30 std::string &
BuildResponse(std::string code, std::string message);
40 static std::string
urlunescape(
const std::string & in);
41 static std::string
urlencode(
const std::string & in);
57 bool parse(std::string & HTTPbuffer);
61 std::map<std::string, std::string>
headers;
62 std::map<std::string, std::string>
vars;
63 void Trim(std::string & s);
64 static int unhex(
char c);
65 static std::string
hex(
char dec);
void setCORSHeaders()
Sets the neccesary headers to allow Cross Origin Resource Sharing with all domains.
Definition: http_parser.cpp:36
std::string & BuildResponse()
Returns a string containing a valid HTTP 1.0 or 1.1 response, ready for sending.
Definition: http_parser.cpp:119
bool sendingChunks
Definition: http_parser.h:50
void SendResponse(std::string code, std::string message, Socket::Connection &conn)
Creates and sends a valid HTTP 1.0 or 1.1 response.
Definition: http_parser.cpp:130
std::string GetHeader(std::string i)
Returns header i, if set.
Definition: http_parser.cpp:307
bool bufferChunks
Definition: http_parser.h:48
bool Read(Socket::Connection &conn)
Attempt to read a whole HTTP request or response from a Socket::Connection.
Definition: http_parser.cpp:345
void SetBody(std::string s)
Function that sets the body of a response or request, along with the correct Content-Length header...
Definition: http_parser.cpp:283
void StartResponse(std::string code, std::string message, Parser &request, Socket::Connection &conn, bool bufferAllChunks=false)
Creates and sends a valid HTTP 1.0 or 1.1 response, based on the given request.
Definition: http_parser.cpp:157
std::string builder
Definition: http_parser.h:59
std::string GetVar(std::string i)
Returns POST variable i, if set.
Definition: http_parser.cpp:311
void Clean()
Completely re-initializes the HTTP::Parser, leaving it ready for either reading or writing usage...
Definition: http_parser.cpp:15
std::string & BuildRequest()
Returns a string containing a valid HTTP 1.0 or 1.1 request, ready for sending.
Definition: http_parser.cpp:52
std::string url
Definition: http_parser.h:44
std::map< std::string, std::string > vars
Definition: http_parser.h:62
static int unhex(char c)
Helper function for urlunescape.
Definition: http_parser.cpp:639
Holds all HTTP processing related code.
Definition: http_parser.h:12
Simple class for reading and writing HTTP 1.0 and 1.1.
Definition: http_parser.h:14
void SetVar(std::string i, std::string v)
Sets POST variable i to string value v.
Definition: http_parser.cpp:331
void parseVars(std::string data)
Parses GET or POST-style variable data.
Definition: http_parser.cpp:530
void Trim(std::string &s)
Trims any whitespace at the front or back of the string.
Definition: http_parser.cpp:271
std::string getUrl()
Returns header i, if set.
Definition: http_parser.cpp:298
bool seenHeaders
Definition: http_parser.h:53
bool parse(std::string &HTTPbuffer)
Attempt to read a whole HTTP response or request from a data buffer.
Definition: http_parser.cpp:385
static std::string hex(char dec)
Helper function for urlescape.
Definition: http_parser.cpp:661
unsigned int doingChunk
Definition: http_parser.h:56
static std::string urlencode(const std::string &in)
URLencodes std::string data.
Definition: http_parser.cpp:644
std::string protocol
Definition: http_parser.h:45
bool headerOnly
If true, do not parse body if the length is a known size.
Definition: http_parser.h:47
void CleanPreserveHeaders()
Completely re-initializes the HTTP::Parser, leaving it ready for either reading or writing usage...
Definition: http_parser.cpp:21
unsigned int length
Definition: http_parser.h:46
bool seenReq
Definition: http_parser.h:54
bool getChunks
Definition: http_parser.h:55
static std::string urlunescape(const std::string &in)
Unescapes URLencoded std::string data.
Definition: http_parser.cpp:612
std::map< std::string, std::string > headers
Definition: http_parser.h:61
std::string read_buffer
Definition: http_parser.h:60
void Proxy(Socket::Connection &from, Socket::Connection &to)
After receiving a header with this object, and after a call with SendResponse/SendRequest with this o...
Definition: http_parser.cpp:187
This class is for easy communicating through sockets, either TCP or Unix.
Definition: socket.h:47
Parser()
This constructor creates an empty HTTP::Parser, ready for use for either reading or writing...
Definition: http_parser.cpp:9
std::string method
Definition: http_parser.h:43
std::string body
Definition: http_parser.h:42
void SendRequest(Socket::Connection &conn)
Creates and sends a valid HTTP 1.0 or 1.1 request.
Definition: http_parser.cpp:71
void Chunkify(const std::string &bodypart, Socket::Connection &conn)
Sends a string in chunked format if protocol is HTTP/1.1, sends as-is otherwise.
Definition: http_parser.cpp:563
void SetHeader(std::string i, std::string v)
Sets header i to string value v.
Definition: http_parser.cpp:316