Unique object to wait for and access a HTTP response data. More...
Public Member Functions | |
Constructors, assignment operators and destructor | |
BHttpResult (const BHttpResult &other)=delete | |
Copy constructor is disabled. | |
BHttpResult (BHttpResult &&other) noexcept | |
Move constructor. | |
~BHttpResult () | |
Destructor. | |
BHttpResult & | operator= (const BHttpResult &other)=delete |
Copy assignment is disabled. | |
BHttpResult & | operator= (BHttpResult &&other) noexcept |
Move operator. | |
Blocking Data Access | |
const BHttpStatus & | Status () const |
Retrieve the status line of the HTTP response. | |
const BHttpFields & | Fields () const |
Retrieve the header fields of the HTTP response. | |
BHttpBody & | Body () const |
Retrieve the body of the HTTP response. | |
Non-blocking status functions | |
bool | HasStatus () const |
Check if the status is available. | |
bool | HasFields () const |
Check if the header fields are available. | |
bool | HasBody () const |
Check if the body is available. | |
bool | IsCompleted () const |
Check if the request is completed. | |
int32 | Identity () const |
Unique identifier for the response. | |
Unique object to wait for and access a HTTP response data.
Once you have scheduled a HTTP request in a HTTP session, you will get an object of this type as a return value. This object allows you to track the progress of receiving the response, and to inspect the status, the headers and the data as the response is received from the server.
The object is a future type, meaning that eventually it will contain the data or an error. The Status(), Fields() and Body() methods will yield the respective data. If it is not yet received, they will block until it is available. You can also use the non-blocking methods to check if data is available yet.
The result can either be a partial or completed HTTP Response, or an error. The partial aspect is represented by the fact that the status line, the fields and the body are loaded progressively and can be accessed as soon as they have been received. The meaning of a HTTP response is defined by the HTTP standards. For example, a GET request can return a response with a 200 status code, a set of headers and a body. But it can also return a 404 response, indicating that the resource was not found at the location. It is important to note that both responses are valid HTTP responses within the context of this API. This means that you can still use the access methods of this class to access data from the 404 response without raising an exception.
When there are errors during the request that lead to the situation where there is no valid response according to the HTTP specification, then this object goes into an error state. This means that the access methods of this object will throw an exception of the BNetworkRequestError type.
A special property of this object is that it is unique. This means it cannot be copied, only moved. Objects that have moved from, are in an invalid state, and will always raise a BRuntimeError exception when they are used.
|
delete |
Copy constructor is disabled.
These objects cannot be copied.
|
noexcept |
Move constructor.
other | The object to move from. The other object will be in an invalid state and will always throw exceptions when it is used. |
BPrivate::Network::BHttpResult::~BHttpResult | ( | ) |
Destructor.
BHttpBody & BPrivate::Network::BHttpResult::Body | ( | ) | const |
Retrieve the body of the HTTP response.
If the body is not yet available, then this method call will block until it is. You can use the HasBody() method to do a non-blocking check if the status is available.
The lifetime of the body is tied to the lifetime of this response result object. If you want to keep the body beyond that time, you can copy or move the data from the BHttpBody object.
BRuntimeException | This exception is raised when the object has been moved from and is thus no longer valid. |
BNetworkRequestError | This exception is raised when there was an error that prevented completely retrieving and parsing the HTTP response. |
const BHttpFields & BPrivate::Network::BHttpResult::Fields | ( | ) | const |
Retrieve the header fields of the HTTP response.
If the header fields are not yet available, then this method call will block until it is. You can use the HasFields() method to do a non-blocking check if the fields are available.
BRuntimeException | This exception is raised when the object has been moved from and is thus no longer valid. |
BNetworkRequestError | This exception is raised when there was an error that prevented completely retrieving and parsing the HTTP response. |
bool BPrivate::Network::BHttpResult::HasBody | ( | ) | const |
Check if the body is available.
true | The body of the response is available using the Body() method. |
false | The body is not yet available. Any call to Body() will block. |
BRuntimeException | This exception is raised when the object has been moved from and is thus no longer valid. |
bool BPrivate::Network::BHttpResult::HasFields | ( | ) | const |
Check if the header fields are available.
true | The header fields of the response is available using the Fields() method. |
false | They are not yet available. Any call to Fields() will block. |
BRuntimeException | This exception is raised when the object has been moved from and is thus no longer valid. |
bool BPrivate::Network::BHttpResult::HasStatus | ( | ) | const |
Check if the status is available.
true | The status line of the response is available using the Status() method. |
false | The line is not yet available. Any call to Status() will block. |
BRuntimeException | This exception is raised when the object has been moved from and is thus no longer valid. |
int32 BPrivate::Network::BHttpResult::Identity | ( | ) | const |
Unique identifier for the response.
The identifier can be used to cancel requests in a BHttpSession. It can also be uses to check incoming asynchronous event messages against the response.
BRuntimeException | This exception is raised when the object has been moved from and is thus no longer valid. |
bool BPrivate::Network::BHttpResult::IsCompleted | ( | ) | const |
Check if the request is completed.
A request is completed when the status, headers and body have been received, or an error was raised while receiving the data.
BRuntimeException | This exception is raised when the object has been moved from and is thus no longer valid. |
|
noexcept |
Move operator.
other | The object to move from. The other object will be in an invalid state and will always throw exceptions when it is used. |
|
delete |
Copy assignment is disabled.
These objects cannot be copied.
const BHttpStatus & BPrivate::Network::BHttpResult::Status | ( | ) | const |
Retrieve the status line of the HTTP response.
If the status line is not yet available, then this method call will block until it is. You can use the HasStatus() method to do a non-blocking check if the status is available.
BRuntimeException | This exception is raised when the object has been moved from and is thus no longer valid. |
BNetworkRequestError | This exception is raised when there was an error that prevented completely retrieving and parsing the HTTP response. |