Request Class Reference

#include <Pt/Http/Request.h>

HTTP request message. More...

Inherits Message.

Public Member Functions

 Request (Http::Connection &conn)
 Construct with connection.
 Request (Http::Connection &conn, const std::string &url)
 Construct with connection and URL.
 Request (Http::Connection &conn, const char *url)
 Construct with connection and URL.
const std::string & url () const
 Returns the HTTP request URL.
void setUrl (const std::string &u)
 Sets the request URL.
void setUrl (const char *u)
 Sets the request URL.
const std::string & method () const
 Returns the HTTP request method.
void setMethod (const std::string &m)
 Sets the request method.
void setMethod (const char *m)
 Sets the request method.
const std::string & qparams () const
 Returns the HTTP request URL query.
void setQParams (const std::string &p)
 Sets the URL query string.
void setQParams (const char *p)
 Sets the URL query string.
void clear ()
 Clears all content.
Connection & connection ()
 Returns the used connection.
MessageHeaderheader ()
 Returns the header of the message.
const MessageHeaderheader () const
 Returns the header of the message.
std::iostream & body ()
 Returns the body of the message.
std::size_t available () const
 Returns the number of bytes available to read.
std::size_t pending () const
 Returns the number of bytes pending to be written.
void discard ()
 Discards the message body.

Detailed Description

Request is the Message a client sends and a server receives. It adds the request line: method, URL and query string. The default method is GET. setUrl() sets the resource path, setMethod() sets the verb, and setQParams() sets the query without the leading question mark. Header fields and the body are the inherited Message operations.

On the client, the request is Client::request(). Fill it before beginSend() or beginReceive(), including keep-alive or content headers that the exchange needs. On the server, the responder receives it in onBeginRequest() and onReadRequest(), where the header is already parsed and the body arrives in chunks.

clear() resets URL, method, query and the inherited header and body so the same request object can be filled for another exchange. Send and receive on Request itself are used by the connection; the client API is Client::beginSend() and Client::beginReceive().