TSDuck v3.46-4964
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::WebRequestStatus Class Reference

#include <tsWebRequestStatus.h>

Public Member Functions

 WebRequestStatus (const UString &url=UString())
void addContentSize (size_t size)
void addTotalRawDataSize (size_t size)
size_t announcedContentSize () const
size_t contentSize () const
const UString & finalURL () const
bool httpClientError () const
bool httpRedirection () const
bool httpServerError () const
int httpStatus () const
bool httpSuccess () const
UString mimeType (bool simple=true, bool lowercase=true) const
const UString & originalURL () const
void processReponseHeaders (const UString &text, Report &report)
UString reponseHeader (const UString &name) const
void reset (const UString &url=UString())
const UStringToUStringMultiMap & responseHeaders () const
void setContentSize (size_t size)
void setFinalURL (const UString &url, bool only_if_different=false)
void setHttpStatus (int status)
void setTotalRawDataSize (size_t size)
size_t totalRawDataSize () const

Detailed Description

Status of a WebRequest.

Constructor & Destructor Documentation

◆ WebRequestStatus()

ts::WebRequestStatus::WebRequestStatus ( const UString & url = UString())

Constructor.

Parameters
[in]urlOptional original URL of the request.

Member Function Documentation

◆ reset()

void ts::WebRequestStatus::reset ( const UString & url = UString())

Reset the WebRequest status. This method is typically used before starting a new request.

Parameters
[in]urlOptional original URL of the request.

◆ originalURL()

const UString & ts::WebRequestStatus::originalURL ( ) const
inline

Get the original URL, as set by the constructor or reset().

Returns
A constant reference to the original URL.

◆ finalURL()

const UString & ts::WebRequestStatus::finalURL ( ) const
inline

Get the final URL of the actual download operation. It can be different from originalURL() if some HTTP redirections were performed. When called before a download operation, return originalURL(). If redirections are disabled using WebRequestArgs::setAutoRedirect() and the site returned a redirection, finalURL() returns the redirected URL.

Returns
A constant reference to the final / redirected URL.

◆ setFinalURL()

void ts::WebRequestStatus::setFinalURL ( const UString & url,
bool only_if_different = false )

Set the final URL of the actual download operation.

Parameters
[in]urlThe final URL.
[in]only_if_differentIf true, do not set the final URL if url is the same value as the original URL. If false (the default), the final URL is unconditionally set with the value of url.

◆ processReponseHeaders()

void ts::WebRequestStatus::processReponseHeaders ( const UString & text,
Report & report )

Process a list of response headers. Set response headers and HTTP status when present. When header "Location" is found, set the final URL to the specified redirection. When header "Content-length" is found, set the announced content size.

Parameters
[in]textMulti-line HTTP response text. If it starts from the beginning of the session response (initial "HTTP/" header), the HTTP status is extracted. Header lines are terminated by LF or CR-LF.
[in,out]reportWhere to report debug messages.

◆ httpStatus()

int ts::WebRequestStatus::httpStatus ( ) const
inline

Get the HTTP status code (200, 404, etc).

Returns
The HTTP status code.

◆ setHttpStatus()

void ts::WebRequestStatus::setHttpStatus ( int status)
inline

Set the HTTP status code (200, 404, etc). Note that the HTTP status can also be set using processReponseHeaders().

Parameters
[in]statusThe HTTP status code.
See also
processReponseHeaders()

◆ httpSuccess()

bool ts::WebRequestStatus::httpSuccess ( ) const
inline

Check if the HTTP status code indicates success. The HTTP status codes are classified as follow (Wikipedia):

  • 1xx informational response – the request was received, continuing process
  • 2xx successful – the request was successfully received, understood, and accepted
  • 3xx redirection – further action needs to be taken in order to complete the request
  • 4xx client error – the request contains bad syntax or cannot be fulfilled
  • 5xx server error – the server failed to fulfil an apparently valid request
    Returns
    True if the HTTP status code indicates success.

◆ httpRedirection()

bool ts::WebRequestStatus::httpRedirection ( ) const
inline

Check if the HTTP status code indicates a redirection. Redirection codes are 3xx (eg. "HTTP/1.1 301 Moved Permanently").

Returns
True if the HTTP status code indicates a redirection.

◆ httpClientError()

bool ts::WebRequestStatus::httpClientError ( ) const
inline

Check if the HTTP status code indicates a client error.

Returns
True if the HTTP status code indicates a client error.

◆ httpServerError()

bool ts::WebRequestStatus::httpServerError ( ) const
inline

Check if the HTTP status code indicates a server error.

Returns
True if the HTTP status code indicates a server error.

◆ announcedContentSize()

size_t ts::WebRequestStatus::announcedContentSize ( ) const
inline

Get the announced content size in bytes. This is the value which was sent in the response headers. This may be zero, this may not be the actual size of the content to download.

Returns
Announced content size in bytes.

◆ contentSize()

size_t ts::WebRequestStatus::contentSize ( ) const
inline

Get the size in bytes of the downloaded content. It must be set by the application when the actual content was downloaded.

Returns
Size in bytes of the downloaded content.

◆ setContentSize()

void ts::WebRequestStatus::setContentSize ( size_t size)
inline

Set the size in bytes of the downloaded content.

Parameters
[in]sizeSize in bytes of the downloaded content.

◆ addContentSize()

void ts::WebRequestStatus::addContentSize ( size_t size)
inline

Add a value to the size in bytes of the downloaded content. Can be called each time a chunk of downloaded data is received.

Parameters
[in]sizeSize in bytes of the additional downloaded content.

◆ totalRawDataSize()

size_t ts::WebRequestStatus::totalRawDataSize ( ) const
inline

Get the size in bytes of the total raw downloaded data (headers and content). It must be set by the application when the actual content was downloaded.

Returns
Size in bytes of the total raw downloaded data.

◆ setTotalRawDataSize()

void ts::WebRequestStatus::setTotalRawDataSize ( size_t size)
inline

Set the size in bytes of the total raw downloaded data (headers and content).

Parameters
[in]sizeSize in bytes of the total raw downloaded data (headers and content).

◆ addTotalRawDataSize()

void ts::WebRequestStatus::addTotalRawDataSize ( size_t size)
inline

Add a value to the size in bytes of the total raw downloaded data (headers and content). Can be called each time a chunk of downloaded data is received.

Parameters
[in]sizeSize in bytes of the additional total raw downloaded data (headers and content).

◆ responseHeaders()

const UStringToUStringMultiMap & ts::WebRequestStatus::responseHeaders ( ) const
inline

Get all response headers.

Returns
A constant reference to a map of response headers.

◆ reponseHeader()

UString ts::WebRequestStatus::reponseHeader ( const UString & name) const

Get the value of one response header.

Parameters
[in]nameHeader name, not case sensitive.
Returns
Header value or an empty string when the header is not found. If the header is present more than once, the first value is returned.

◆ mimeType()

UString ts::WebRequestStatus::mimeType ( bool simple = true,
bool lowercase = true ) const

Get the MIME type in the response headers.

Parameters
[in]simpleIf true, simple type name. If false, return the full specification with options.
[in]lowercaseForce lowercase in the result.
Returns
The MIME type.

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