Loading...
Searching...
No Matches
List of all members
BPrivate::Network::BHttpResult Class Reference

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.
 
BHttpResultoperator= (const BHttpResult &other)=delete
 Copy assignment is disabled.
 
BHttpResultoperator= (BHttpResult &&other) noexcept
 Move operator.
 
Blocking Data Access
const BHttpStatusStatus () const
 Retrieve the status line of the HTTP response.
 
const BHttpFieldsFields () const
 Retrieve the header fields of the HTTP response.
 
BHttpBodyBody () 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.
 

Detailed Description

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.

Since
Haiku R1

Constructor & Destructor Documentation

◆ BHttpResult() [1/2]

BPrivate::Network::BHttpResult::BHttpResult ( const BHttpResult other)
delete

Copy constructor is disabled.

These objects cannot be copied.

Since
Haiku R1

◆ BHttpResult() [2/2]

BPrivate::Network::BHttpResult::BHttpResult ( BHttpResult &&  other)
noexcept

Move constructor.

Parameters
otherThe object to move from. The other object will be in an invalid state and will always throw exceptions when it is used.
Since
Haiku R1

◆ ~BHttpResult()

BPrivate::Network::BHttpResult::~BHttpResult ( )

Destructor.

Since
Haiku R1

Member Function Documentation

◆ Body()

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.

Returns
A reference to the BHttpBody object that contains the body.
Exceptions
BRuntimeExceptionThis exception is raised when the object has been moved from and is thus no longer valid.
BNetworkRequestErrorThis exception is raised when there was an error that prevented completely retrieving and parsing the HTTP response.
Since
Haiku R1

◆ Fields()

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.

Returns
A const reference to the BHttpFields object that describes the header fields of the response.
Exceptions
BRuntimeExceptionThis exception is raised when the object has been moved from and is thus no longer valid.
BNetworkRequestErrorThis exception is raised when there was an error that prevented completely retrieving and parsing the HTTP response.
Since
Haiku R1

◆ HasBody()

bool BPrivate::Network::BHttpResult::HasBody ( ) const

Check if the body is available.

Return values
trueThe body of the response is available using the Body() method.
falseThe body is not yet available. Any call to Body() will block.
Exceptions
BRuntimeExceptionThis exception is raised when the object has been moved from and is thus no longer valid.
Since
Haiku R1

◆ HasFields()

bool BPrivate::Network::BHttpResult::HasFields ( ) const

Check if the header fields are available.

Return values
trueThe header fields of the response is available using the Fields() method.
falseThey are not yet available. Any call to Fields() will block.
Exceptions
BRuntimeExceptionThis exception is raised when the object has been moved from and is thus no longer valid.
Since
Haiku R1

◆ HasStatus()

bool BPrivate::Network::BHttpResult::HasStatus ( ) const

Check if the status is available.

Return values
trueThe status line of the response is available using the Status() method.
falseThe line is not yet available. Any call to Status() will block.
Exceptions
BRuntimeExceptionThis exception is raised when the object has been moved from and is thus no longer valid.
Since
Haiku R1

◆ Identity()

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.

Returns
A unique identifier that associates this response with an active or completed request.
Exceptions
BRuntimeExceptionThis exception is raised when the object has been moved from and is thus no longer valid.
Since
Haiku R1

◆ IsCompleted()

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.

Exceptions
BRuntimeExceptionThis exception is raised when the object has been moved from and is thus no longer valid.
Since
Haiku R1

◆ operator=() [1/2]

BHttpResult & BPrivate::Network::BHttpResult::operator= ( BHttpResult &&  other)
noexcept

Move operator.

Parameters
otherThe object to move from. The other object will be in an invalid state and will always throw exceptions when it is used.
Since
Haiku R1

◆ operator=() [2/2]

BHttpResult & BPrivate::Network::BHttpResult::operator= ( const BHttpResult other)
delete

Copy assignment is disabled.

These objects cannot be copied.

Since
Haiku R1

◆ Status()

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.

Returns
A const reference to the BHttpStatus object that describes the status of the response.
Exceptions
BRuntimeExceptionThis exception is raised when the object has been moved from and is thus no longer valid.
BNetworkRequestErrorThis exception is raised when there was an error that prevented completely retrieving and parsing the HTTP response.
Since
Haiku R1