|
STTNet
|
Operation class for parsing and responding to Http/https requests Only pass in the socket, then use this class for Http operations. More...
#include <sttnet_English.h>
Public Member Functions | |
| void | setFD (const int &fd, SSL *ssl=nullptr, const bool &flag1=false, const bool &flag2=true) |
| Initialize the object, pass in socket and other parameters. More... | |
| int | solveRequest (TcpFDInf &TcpInf, HttpRequestInformation &HttpInf, const unsigned long &buffer_size, const int ×=1) |
| Parse Http/Https request. More... | |
| bool | sendBack (const std::string &data, const std::string &header="", const std::string &code="200 OK", const std::string &header1="") |
| Send Http/Https response. More... | |
| bool | sendBack (const char *data, const size_t &length, const char *header="\0", const char *code="200 OK\0", const char *header1="\0", const size_t &header_length=50) |
| Send Http/Https response. More... | |
Public Member Functions inherited from stt::network::TcpFDHandler | |
| void | setFD (const int &fd, SSL *ssl, const bool &flag1=false, const bool &flag2=false, const int &sec=-1) |
| Initialize the object with a socket. More... | |
| int | getFD () |
| Get the socket of this object. More... | |
| SSL * | getSSL () |
| Get the encrypted SSL handle of this object. More... | |
| void | close (const bool &cle=true) |
| Close the object. More... | |
| void | blockSet (const int &sec=-1) |
| Set the socket in the object to blocking mode. More... | |
| void | unblockSet () |
| Set the socket in the object to non-blocking mode. More... | |
| bool | multiUseSet () |
| Set the socket in the object to SO_REUSEADDR mode. More... | |
| bool | isConnect () |
| Determine if the object has a socket bound. More... | |
| int | sendData (const std::string &data, const bool &block=true) |
| Send string data to the connected socket. More... | |
| int | sendData (const char *data, const uint64_t &length, const bool &block=true) |
| Send a specified length of binary data to the connected socket. More... | |
| int | recvDataByLength (std::string &data, const uint64_t &length, const int &sec=2) |
| Blocking receive of specified length of data from a connected socket into a string. More... | |
| int | recvDataByLength (char *data, const uint64_t &length, const int &sec=2) |
| Blocking receive of specified length of data from a connected socket into a char* container. More... | |
| int | recvData (std::string &data, const uint64_t &length) |
| Receive data once from a connected socket into a string container. More... | |
| int | recvData (char *data, const uint64_t &length) |
| Receive data once from a connected socket into a char* container. More... | |
Additional Inherited Members | |
Public Attributes inherited from stt::network::TcpFDHandler | |
| bool | flag3 = false |
| if the connection lost while using sendData function with block=true,this flag will be set to true More... | |
Protected Attributes inherited from stt::network::TcpFDHandler | |
| int | fd = -1 |
| bool | flag1 = false |
| bool | flag2 = false |
| SSL * | ssl = nullptr |
| int | sec =-1 |
Operation class for parsing and responding to Http/https requests Only pass in the socket, then use this class for Http operations.
| bool stt::network::HttpServerFDHandler::sendBack | ( | const std::string & | data, |
| const std::string & | header = "", |
||
| const std::string & | code = "200 OK", |
||
| const std::string & | header1 = "" |
||
| ) |
Send Http/Https response.
| data | String container with response body data |
| code | Http response status code and status description (default is "200 OK") |
| header | Http request header; if not generated by createHeader, remember to add at the end. |
| header1 | Additional item for the HTTP request header; if needed, must fill in a valid item; no need to add at the end (cannot use createHeader). (For example, you can fill in the keepalive field by default) |
| bool stt::network::HttpServerFDHandler::sendBack | ( | const char * | data, |
| const size_t & | length, | ||
| const char * | header = "\0", |
||
| const char * | code = "200 OK\0", |
||
| const char * | header1 = "\0", |
||
| const size_t & | header_length = 50 |
||
| ) |
Send Http/Https response.
| data | Char * container with response body data |
| length | Data length in the char* container |
| code | Http response status code and status description (default is "200 OK") |
| header | Http request header; if not generated by createHeader, remember to add at the end. |
| header1 | Additional item for the HTTP request header; if needed, must fill in a valid item; no need to add at the end (cannot use createHeader). (For example, you can fill in the keepalive field by default) |
| header_length | Maximum length of the response header added up (default is 50) |
|
inline |
Initialize the object, pass in socket and other parameters.
| fd | Socket |
| ssl | TLS encrypted SSL handle (default is nullptr) |
| flag1 | true: Enable non-blocking mode, false: Enable blocking mode (default is false, i.e., blocking mode) |
| flag2 | true: Enable SO_REUSEADDR mode, false: Do not enable SO_REUSEADDR mode (default is true, i.e., enable mode) |
| int stt::network::HttpServerFDHandler::solveRequest | ( | TcpFDInf & | TcpInf, |
| HttpRequestInformation & | HttpInf, | ||
| const unsigned long & | buffer_size, | ||
| const int & | times = 1 |
||
| ) |
Parse Http/Https request.
| TcpInf | stores the state information of the underlying TCP processing socket |
| HttpInf | stores the information of Http |
| buffer_size | The size of the server-defined parsing buffer (in bytes) |
| times | sometims will be used to record solve times |
0 Initial status 1 Receive request header 2 Receive request body (chunk mode) 3 Receive request body (non-chunk mode)
1.8.5