83 Request(
const std::string& uri =
"/",
Method method = Method::Get,
const std::string& body =
"");
98 void setField(
const std::string& field,
const std::string& value);
159 [[nodiscard]] std::string prepare()
const;
171 [[nodiscard]]
bool hasField(
const std::string& field)
const;
176 using FieldTable = std::map<std::string, std::string>;
184 unsigned int m_majorVersion{1};
185 unsigned int m_minorVersion{};
208 PartialContent = 206,
211 MultipleChoices = 300,
212 MovedPermanently = 301,
213 MovedTemporarily = 302,
221 RangeNotSatisfiable = 407,
224 InternalServerError = 500,
225 NotImplemented = 501,
227 ServiceNotAvailable = 503,
228 GatewayTimeout = 504,
229 VersionNotSupported = 505,
232 InvalidResponse = 1000,
233 ConnectionFailed = 1001
248 [[nodiscard]]
const std::string&
getField(
const std::string& field)
const;
295 [[nodiscard]]
const std::string&
getBody()
const;
309 void parse(
const std::string& data);
321 void parseFields(std::istream& in);
326 using FieldTable = std::map<std::string, std::string>;
332 Status m_status{Status::ConnectionFailed};
333 unsigned int m_majorVersion{};
334 unsigned int m_minorVersion{};
358 Http(
const std::string& host,
unsigned short port = 0);
387 void setHost(
const std::string& host,
unsigned short port = 0);
414 std::optional<IpAddress> m_host;
415 std::string m_hostName;
416 unsigned short m_port{};
void setUri(const std::string &uri)
Set the requested URI.
Method
Enumerate the available HTTP methods for a request.
void setHttpVersion(unsigned int major, unsigned int minor)
Set the HTTP version for the request.
void setMethod(Method method)
Set the request method.
Request(const std::string &uri="/", Method method=Method::Get, const std::string &body="")
Default constructor.
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.
Status getStatus() const
Get the response status code.
Status
Enumerate all the valid status codes for a response.
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.
Http(const Http &)=delete
Deleted copy constructor.
void setHost(const std::string &host, unsigned short port=0)
Set the target host.
Http & operator=(const Http &)=delete
Deleted copy assignment.
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
Default constructor.
Specialized socket using the TCP protocol.