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

A Response is used to capture exceptions and response headers. More...

#include <Response.h>

Inheritance diagram for ofx::HTTP::Response:

Public Member Functions

virtual ~Response ()
 Destroy the Response.
 
int64_t estimatedContentLength () const
 Calculate the estimated content length. More...
 
virtual bool hasResponseStream () const
 
virtual std::istream & stream ()
 Get the data stream. More...
 
bool isBufferable () const
 Determine if the response can be buffered. More...
 
bool isBuffered () const
 
ofBuffer buffer ()
 Get the buffer, if available. More...
 
IO::ByteBuffer byteBuffer ()
 Get the byte buffer, if available. More...
 
bool isPixels () const
 
ofPixels pixels ()
 Get response as ofPixels. More...
 
bool isJson () const
 
ofJson json ()
 Get response as ofJson. More...
 
bool isXml () const
 
ofXml xml ()
 Get response as ofXml. More...
 
bool toFile (const std::filesystem::path &path)
 Save the buffer contents to a file. More...
 
bool isInformational () const
 Determine if this response is informational. More...
 
bool isSuccess () const
 Determine if this response is a success. More...
 
bool isRedirection () const
 Determine if this response is a redirection. More...
 
bool isClientError () const
 Determine if this response is a client error. More...
 
bool isServerError () const
 Determine if this response is a server error. More...
 
std::string statusAndReason () const
 

Static Public Attributes

static const std::string CONTENT_RANGE = "Content-Range"
 A constant value representing Content-Range.
 
static const std::string BYTES_UNIT = "bytes"
 A constant value representing a byte.
 

Friends

class BaseClient
 
class Client
 

Detailed Description

A Response is used to capture exceptions and response headers.

The user must ask for the input stream from the client or use a Buffered Response to receive the data.

Member Function Documentation

◆ buffer()

ofBuffer ofx::HTTP::Response::buffer ( )

Get the buffer, if available.

Returns
response or an empty buffer if the response can't be buffered.

◆ byteBuffer()

IO::ByteBuffer ofx::HTTP::Response::byteBuffer ( )

Get the byte buffer, if available.

Returns
response or an empty buffer if the response can't be buffered.

◆ estimatedContentLength()

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

Calculate the estimated content length.

This is based upon the given Content-Length header, or other information if the Content-Length header is not available.

Returns
estimated content length or UNKNOWN_CONTENT_LENGTH if unknown.

◆ hasResponseStream()

bool ofx::HTTP::Response::hasResponseStream ( ) const
virtual
Returns
true of this response has a valid response stream.

◆ isBufferable()

bool ofx::HTTP::Response::isBufferable ( ) const

Determine if the response can be buffered.

This is equivalent to checking if

return estimatedContentLength() != UNKNOWN_CONTENT_LENGTH.
Returns
true if this stream can be buffered.

◆ isBuffered()

bool ofx::HTTP::Response::isBuffered ( ) const
Returns
true if the stream has already been buffered.

◆ isClientError()

bool ofx::HTTP::Response::isClientError ( ) const

Determine if this response is a client error.

See also
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
Returns
true if the HTTP response code is >= 400 and < 500.

◆ isInformational()

bool ofx::HTTP::Response::isInformational ( ) const

Determine if this response is informational.

See also
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
Returns
true if the HTTP response code is >= 100 and < 200.

◆ isJson()

bool ofx::HTTP::Response::isJson ( ) const
Returns
true if the CONTENT-TYPE header is text/json or application/json.

◆ isPixels()

bool ofx::HTTP::Response::isPixels ( ) const
Returns
true if the CONTENT-TYPE matches image/*.

◆ isRedirection()

bool ofx::HTTP::Response::isRedirection ( ) const

Determine if this response is a redirection.

See also
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
Returns
true if the HTTP response code is >= 300 and < 400.

◆ isServerError()

bool ofx::HTTP::Response::isServerError ( ) const

Determine if this response is a server error.

See also
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
Returns
true if the HTTP response code is >= 500.

◆ isSuccess()

bool ofx::HTTP::Response::isSuccess ( ) const

Determine if this response is a success.

See also
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
Returns
true if the HTTP response code is >= 200 and < 300.

◆ isXml()

bool ofx::HTTP::Response::isXml ( ) const
Returns
true if the CONTENT-TYPE header is text/xml or application/xml.

◆ json()

ofJson ofx::HTTP::Response::json ( )

Get response as ofJson.

Returns
empty json if the response can't be buffered or json can't be parsed.

◆ pixels()

ofPixels ofx::HTTP::Response::pixels ( )

Get response as ofPixels.

Returns
empty pixels if the response can't be buffered or pixels can't be loaded.

◆ statusAndReason()

std::string ofx::HTTP::Response::statusAndReason ( ) const
Returns
a string representing the response status and reason.

◆ stream()

std::istream & ofx::HTTP::Response::stream ( )
virtual

Get the data stream.

stream() returns the response input stream. If the stream can be buffered (i.e. its content length is finite and known), the content will be be buffered. Subsequent calls to stream() will present the buffered data as a stream. Buffered data can also be accessed via the buffer() method.

If the stream cannot be buffered (i.e. it is a streaming connection and its content is not finite or known), the content will not be buffered. In this case attempts to call stream() after it has been consumed may result in an exception.

Returns
the response stream.

◆ toFile()

bool ofx::HTTP::Response::toFile ( const std::filesystem::path &  path)

Save the buffer contents to a file.

Internally calls buffer() and saves the contents to the path.

Parameters
fileThe path to save the buffer.
Returns
true if the file save operation was successful.

◆ xml()

ofXml ofx::HTTP::Response::xml ( )

Get response as ofXml.

Returns
empty xml if the response can't be buffered or xml can't be parsed.

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