31#include <SFML/Network/Export.hpp>
32#include <SFML/Network/IpAddress.hpp>
33#include <SFML/Network/TcpSocket.hpp>
34#include <SFML/System/NonCopyable.hpp>
35#include <SFML/System/Time.hpp>
82 Request(
const std::string& uri =
"/",
Method method =
Get,
const std::string& body =
"");
97 void setField(
const std::string& field,
const std::string& value);
159 std::string prepare()
const;
171 bool hasField(
const std::string& field)
const;
176 typedef std::map<std::string, std::string> FieldTable;
184 unsigned int m_majorVersion;
185 unsigned int m_minorVersion;
257 const std::string&
getField(
const std::string& field)
const;
319 void parse(
const std::string& data);
331 void parseFields(std::istream &in);
336 typedef std::map<std::string, std::string> FieldTable;
343 unsigned int m_majorVersion;
344 unsigned int m_minorVersion;
368 Http(
const std::string& host,
unsigned short port = 0);
385 void setHost(
const std::string& host,
unsigned short port = 0);
414 std::string m_hostName;
415 unsigned short m_port;
void setUri(const std::string &uri)
Set the requested URI.
Method
Enumerate the available HTTP methods for a request.
@ Head
Request a page's header only.
@ Put
Request in put mode, useful for a REST API.
@ Get
Request in get mode, standard method to retrieve a page.
@ Delete
Request in delete mode, useful for a REST API.
@ Post
Request in post mode, usually to send data to a page.
Request(const std::string &uri="/", Method method=Get, const std::string &body="")
Default constructor.
void setHttpVersion(unsigned int major, unsigned int minor)
Set the HTTP version for the request.
void setMethod(Method method)
Set the request method.
void setBody(const std::string &body)
Set the body of the request.
void setField(const std::string &field, const std::string &value)
Set the value of a field.
Response()
Default constructor.
Status getStatus() const
Get the response status code.
Status
Enumerate all the valid status codes for a response.
@ Ok
Most common code returned when operation was successful.
@ MovedTemporarily
The requested page has temporarily moved to a new location.
@ NotModified
For conditional requests, means the requested page hasn't changed and doesn't need to be refreshed.
@ Created
The resource has successfully been created.
@ InvalidResponse
Response is not a valid HTTP one.
@ PartialContent
The server has sent a part of the resource, as a response to a partial GET request.
@ RangeNotSatisfiable
The server can't satisfy the partial GET request (with a "Range" header field)
@ GatewayTimeout
The gateway server couldn't receive a response from the source server.
@ MovedPermanently
The requested page has permanently moved to a new location.
@ BadRequest
The server couldn't understand the request (syntax error)
@ Forbidden
The requested page cannot be accessed at all, even with authentication.
@ NotImplemented
The server doesn't implement a requested feature.
@ ResetContent
The server informs the client that it should clear the view (form) that caused the request to be sent...
@ ConnectionFailed
Connection with server failed.
@ BadGateway
The gateway server has received an error from the source server.
@ Unauthorized
The requested page needs an authentication to be accessed.
@ ServiceNotAvailable
The server is temporarily unavailable (overloaded, in maintenance, ...)
@ Accepted
The request has been accepted, but will be processed later by the server.
@ InternalServerError
The server encountered an unexpected error.
@ MultipleChoices
The requested page can be accessed from several locations.
@ VersionNotSupported
The server doesn't support the requested HTTP version.
@ NoContent
The server didn't send any data in return.
@ NotFound
The requested page doesn't exist.
unsigned int getMajorHttpVersion() const
Get the major HTTP version number of the response.
const std::string & getBody() const
Get the body of the response.
const std::string & getField(const std::string &field) const
Get the value of a field.
unsigned int getMinorHttpVersion() const
Get the minor HTTP version number of the response.
void setHost(const std::string &host, unsigned short port=0)
Set the target host.
Http(const std::string &host, unsigned short port=0)
Construct the HTTP client with the target host.
Response sendRequest(const Request &request, Time timeout=Time::Zero)
Send a HTTP request and return the server's response.
Http()
Default constructor.
Encapsulate an IPv4 network address.
NonCopyable()
Default constructor.
Specialized socket using the TCP protocol.
static const Time Zero
Predefined "zero" time value.