25 #ifndef CPP3DS_HTTP_HPP
26 #define CPP3DS_HTTP_HPP
31 #include <cpp3ds/Network/IpAddress.hpp>
32 #include <cpp3ds/Network/TcpSocket.hpp>
33 #include <cpp3ds/System/NonCopyable.hpp>
34 #include <cpp3ds/System/Time.hpp>
81 Request(
const std::string& uri =
"/",
Method method =
Get,
const std::string& body =
"");
96 void setField(
const std::string& field,
const std::string& value);
120 void setUri(
const std::string& uri);
143 void setBody(
const std::string& body);
158 std::string prepare()
const;
170 bool hasField(
const std::string& field)
const;
175 typedef std::map<std::string, std::string> FieldTable;
183 unsigned int m_majorVersion;
184 unsigned int m_minorVersion;
256 const std::string&
getField(
const std::string& field)
const;
303 const std::string&
getBody()
const;
318 void parse(
const std::string& data);
330 void parseFields(std::istream &in);
335 typedef std::map<std::string, std::string> FieldTable;
342 unsigned int m_majorVersion;
343 unsigned int m_minorVersion;
367 Http(
const std::string& host,
unsigned short port = 0);
384 void setHost(
const std::string& host,
unsigned short port = 0);
413 std::string m_hostName;
414 unsigned short m_port;
420 #endif // CPP3DS_HTTP_HPP
Encapsulate an IPv4 network address.
Method
Enumerate the available HTTP methods for a request.
The requested page can be accessed from several locations.
const std::string & getField(const std::string &field) const
Get the value of a field.
Response sendRequest(const Request &request, Time timeout=Time::Zero)
Send a HTTP request and return the server's response.
Request in get mode, standard method to retrieve a page.
Status getStatus() const
Get the response status code.
Status
Enumerate all the valid status codes for a response.
The gateway server couldn't receive a response from the source server.
Request(const std::string &uri="/", Method method=Get, const std::string &body="")
Default constructor.
The requested page needs an authentication to be accessed.
The server can't satisfy the partial GET request (with a "Range" header field)
void setBody(const std::string &body)
Set the body of the request.
The gateway server has received an error from the source server.
void setHost(const std::string &host, unsigned short port=0)
Set the target host.
void setUri(const std::string &uri)
Set the requested URI.
The server informs the client that it should clear the view (form) that caused the request to be sent...
unsigned int getMajorHttpVersion() const
Get the major HTTP version number of the response.
Request a page's header only.
The request has been accepted, but will be processed later by the server.
The resource has successfully been created.
Connection with server failed.
The server is temporarily unavailable (overloaded, in maintenance, ...)
The requested page cannot be accessed at all, even with authentication.
void setField(const std::string &field, const std::string &value)
Set the value of a field.
Request in put mode, useful for a REST API.
The requested page has temporarily moved to a new location.
const std::string & getBody() const
Get the body of the response.
Response()
Default constructor.
unsigned int getMinorHttpVersion() const
Get the minor HTTP version number of the response.
For conditional requests, means the requested page hasn't changed and doesn't need to be refreshed...
The requested page doesn't exist.
The server doesn't support the requested HTTP version.
The server couldn't understand the request (syntax error)
Utility class that makes any derived class non-copyable.
void setHttpVersion(unsigned int major, unsigned int minor)
Set the HTTP version for the request.
Specialized socket using the TCP protocol.
The server doesn't implement a requested feature.
The server encountered an unexpected error.
Request in delete mode, useful for a REST API.
Most common code returned when operation was successful.
The requested page has permanently moved to a new location.
The server has sent a part of the resource, as a response to a partial GET request.
void setMethod(Method method)
Set the request method.
The server didn't send any data in return.
Http()
Default constructor.
Request in post mode, usually to send data to a page.
static const Time Zero
Predefined "zero" time value.
Response is not a valid HTTP one.