HTTP socket. More...
#include <HttpConnect.h>
Classes | |
class | Authorization |
class | BasicAuthorization |
class | BearerAuthorization |
Public Member Functions | |
HttpConnect (TCPSocket &socket) | |
Constructor. More... | |
HttpHeaders & | requestHeaders () |
Returns the HTTP request headers. More... | |
const HttpHeaders & | responseHeaders () const |
Returns the HTTP headers. More... | |
int | cmd_get (const String &pageName, const HttpParams ¶meters, Buffer &output, const Authorization *authorization=nullptr, std::chrono::milliseconds timeout=std::chrono::seconds(60)) |
Sends the GET command to the server. More... | |
int | cmd_post (const String &pageName, const HttpParams ¶meters, const Buffer &content, Buffer &output, const sptk::Strings &possibleContentEncodings, const Authorization *authorization=nullptr, std::chrono::milliseconds timeout=std::chrono::seconds(60)) |
Sends the POST command to the server. More... | |
int | cmd_put (const String &pageName, const HttpParams ¶meters, const Buffer &content, Buffer &output, const Authorization *authorization=nullptr, std::chrono::milliseconds timeout=std::chrono::seconds(60)) |
Sends the PUT command to the server. More... | |
int | cmd_delete (const String &pageName, const HttpParams ¶meters, Buffer &output, const Authorization *authorization=nullptr, std::chrono::milliseconds timeout=std::chrono::seconds(60)) |
Sends the DELETE command to the server. More... | |
String | responseHeader (const String &headerName) const |
Get value of response header. More... | |
int | statusCode () const |
Get the request execution status code. More... | |
String | statusText () const |
Get the request execution status text. More... | |
Protected Member Functions | |
Strings | makeHeaders (const String &httpCommand, const String &pageName, const HttpParams &requestParameters, const Authorization *authorization) const |
void | sendCommand (const String &cmd) |
Sends a single command to HTTP server. More... | |
void | sendCommand (const Buffer &cmd) |
Sends a single command to HTTP server. More... | |
int | getResponse (Buffer &output, std::chrono::milliseconds timeout) |
Retrieves the server response on the command. More... | |
HTTP socket.
Implements the GET, POST, PUT and DELETE methods of HTTP protocol. Allows to define the host, port, submit information, and then sends the HTML request to the server.
|
explicit |
Constructor.
External socket has to be active before HTTP operations. In order to use HTTPS protocol, use COpenSSLSocket.
socket | external socket |
int sptk::HttpConnect::cmd_delete | ( | const String & | pageName, |
const HttpParams & | parameters, | ||
Buffer & | output, | ||
const Authorization * | authorization = nullptr , |
||
std::chrono::milliseconds | timeout = std::chrono::seconds(60) |
||
) |
Sends the DELETE command to the server.
Retrieves the server response into internal read buffer.
pageName | Page URL without the server name. |
parameters | HTTP request parameters |
output | Output data |
authorization | Optional authorization |
timeout | Request timeout |
int sptk::HttpConnect::cmd_get | ( | const String & | pageName, |
const HttpParams & | parameters, | ||
Buffer & | output, | ||
const Authorization * | authorization = nullptr , |
||
std::chrono::milliseconds | timeout = std::chrono::seconds(60) |
||
) |
Sends the GET command to the server.
Retrieves the server response into internal read buffer.
pageName | Page URL without the server name. |
parameters | HTTP request parameters |
output | Output data |
authorization | Optional authorization |
timeout | Response timeout |
int sptk::HttpConnect::cmd_post | ( | const String & | pageName, |
const HttpParams & | parameters, | ||
const Buffer & | content, | ||
Buffer & | output, | ||
const sptk::Strings & | possibleContentEncodings, | ||
const Authorization * | authorization = nullptr , |
||
std::chrono::milliseconds | timeout = std::chrono::seconds(60) |
||
) |
Sends the POST command to the server.
Retrieves the server response into internal read buffer.
pageName | Page URL without the server name. |
parameters | HTTP request parameters |
content | The data to post to the server |
gzipContent | If true then compress buffer and set HTTP header Content-Encoding |
output | Output data |
authorization | Optional authorization |
timeout | Response timeout |
int sptk::HttpConnect::cmd_put | ( | const String & | pageName, |
const HttpParams & | parameters, | ||
const Buffer & | content, | ||
Buffer & | output, | ||
const Authorization * | authorization = nullptr , |
||
std::chrono::milliseconds | timeout = std::chrono::seconds(60) |
||
) |
Sends the PUT command to the server.
Retrieves the server response into internal read buffer.
pageName | Page URL without the server name. |
parameters | HTTP request parameters |
content | The data to post to the server |
output | Output data |
authorization | Optional authorization |
timeout | Optional response timeout |
|
protected |
Retrieves the server response on the command.
Stops when HTTP server closes the connection. The server response can then be accessed through the htmlData() method.
timeout | Response timeout |
|
protected |
Create default headers for HTTP request
|
inline |
Returns the HTTP request headers.
The HTTP headers request should be set before sending a command to the server
Get value of response header.
headerName | Response header name |
|
inline |
Returns the HTTP headers.
The HTTP response headers make sense only after sending a command to the server (if that command calls getResponse() method internally).
|
protected |
Sends a single command to HTTP server.
CRLF characters are automatically appended to the command.
cmd | HTTP command |
|
protected |
Sends a single command to HTTP server.
CRLF characters are automatically appended to the command.
cmd | HTTP command |
int sptk::HttpConnect::statusCode | ( | ) | const |
Get the request execution status code.
String sptk::HttpConnect::statusText | ( | ) | const |
Get the request execution status text.