ofxHTTP
A collection of tools for HTTP.
ofx::HTTP::Request Class Reference

A Custom Base HTTP Request. More...

#include <Request.h>

Inheritance diagram for ofx::HTTP::Request:
ofx::HTTP::FormRequest ofx::HTTP::JSONRequest ofx::HTTP::GetRequest ofx::HTTP::HeadRequest ofx::HTTP::PostRequest ofx::HTTP::PutRequest

Public Member Functions

 Request (const std::string &method, const std::string &uri, const std::string &httpVersion)
 Construct an Request. More...
 
virtual ~Request ()
 Destroy this Request.
 
virtual void write (std::ostream &ostr) const
 Write the HTTPRequest to an output stream. More...
 
void setRequestId (const std::string &requestId)
 Set the id of the request. More...
 
const std::string & getRequestId () const
 Get the id of the request. More...
 
const Poco::Net::HTMLForm & form () const
 Get a const reference to the raw form data. More...
 
int64_t estimatedContentLength () const
 Get the estimated content length for progress estimation purposes. More...
 

Static Public Member Functions

static std::string generateId ()
 Generate a UUID string. More...
 

Protected Member Functions

virtual void prepareRequest ()
 Prepare the current request.
 
virtual void writeRequestBody (std::ostream &requestStream)
 Write the body of the request. More...
 

Protected Attributes

std::string _requestId
 The original URI passed in during construction. More...
 
Poco::Net::HTMLForm _form
 A form with all query terms / form parameters. More...
 

Friends

class BaseClient
 
class Client
 

Detailed Description

A Custom Base HTTP Request.

Constructor & Destructor Documentation

◆ Request()

ofx::HTTP::Request::Request ( const std::string &  method,
const std::string &  uri,
const std::string &  httpVersion 
)

Construct an Request.

This simple constructor passes the raw URI as is with the Request. Query and fragment parameters included in the URI will not be automatically available for additional processing (e.g. for use in OAuth 1.0 signatures, which require validation of the query/form parameters). Any query parameters added later using the FormRequest::addFormField() methods will be treated as either form fields or URI query parameters depending on the request's HTTP method. Form fields added to POST and PUT requests will be submitted as requests POST and PUT (e.g. GET) will be URL-encoded and appended to the request URI before submission.

If the endpoint URI does not include a host name, the URI will be resolved using the given HTTPSessionClient.

Parameters
methodThe HTTP method (e.g. GET, POST, PUT, etc).
uriThe endpoint URI.
httpVersionEither HTTP/1.0 or HTTP/1.1.
Exceptions
Poco::SyntaxExceptionif the uri is not valid.

Member Function Documentation

◆ estimatedContentLength()

int64_t ofx::HTTP::Request::estimatedContentLength ( ) const

Get the estimated content length for progress estimation purposes.

Internally this will read from the Content-Length header. If that header is not available due to transfer-chunking being true, etc, then it will query the form to calculate the length. Typically, it is not advised to call this function until after any form preparation has been done. If it is not possible to calculate the content length, UNKNOWN_CONTENT_LENGTH will be returned.

Returns
the estimated content length or UNKNOWN_CONTENT_LENGTH if unknown.

◆ form()

const Poco::Net::HTMLForm & ofx::HTTP::Request::form ( ) const

Get a const reference to the raw form data.

This allows read-only access to the raw form data, which prevents inappropriately adding form parts to non POST / PUT requests.

Returns
a const reference to the raw form data.

◆ generateId()

std::string ofx::HTTP::Request::generateId ( )
static

Generate a UUID string.

Returns
a UUID string.

◆ getRequestId()

const std::string & ofx::HTTP::Request::getRequestId ( ) const

Get the id of the request.

Returns
the id of the request.

◆ setRequestId()

void ofx::HTTP::Request::setRequestId ( const std::string &  requestId)

Set the id of the request.

Parameters
requestIdthe id of the request.

◆ write()

void ofx::HTTP::Request::write ( std::ostream &  ostr) const
virtual

Write the HTTPRequest to an output stream.

This method hides the method with the same signature from the base class. While this is not ideal, it allows us to rewrite the request in circumstances where the target servers do not support absolute URI paths.

◆ writeRequestBody()

void ofx::HTTP::Request::writeRequestBody ( std::ostream &  requestStream)
protectedvirtual

Write the body of the request.

Parameters
requestStreamThe stream to write to.

Reimplemented in ofx::HTTP::PutRequest, and ofx::HTTP::JSONRequest.

Member Data Documentation

◆ _form

Poco::Net::HTMLForm ofx::HTTP::Request::_form
mutableprotected

A form with all query terms / form parameters.

This function is not const because the underlying form content length calculator is not const.

◆ _requestId

std::string ofx::HTTP::Request::_requestId
protected

The original URI passed in during construction.

During an HTTP session, the underlying HTTPRequest may modify or otherwise edit the internal URI to meet specifications. This raw URI is stored unmodified for later reference. Poco::URI _rawURI; A unique request id generated for this request.


The documentation for this class was generated from the following files: