A Response is used to capture exceptions and response headers.
More...
#include <Response.h>
|
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 .
|
|
|
class | BaseClient |
|
class | Client |
|
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.
◆ 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 |
◆ isInformational()
bool ofx::HTTP::Response::isInformational |
( |
| ) |
const |
◆ 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 |
◆ isServerError()
bool ofx::HTTP::Response::isServerError |
( |
| ) |
const |
◆ isSuccess()
bool ofx::HTTP::Response::isSuccess |
( |
| ) |
const |
◆ 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
-
file | The 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: