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

#include <tsWebRequestArgs.h>

Public Member Functions

 WebRequestArgs ()=default
void appendRequestHeaders (UString &text) const
bool autoRedirect () const
void clearPostData ()
void clearRequestHeaders ()
bool compressionEnabled () const
cn::milliseconds connectionTimeout () const
bool cookiesEnabled () const
const fs::path & cookiesFileName () const
void defineArgs (Args &args)
void deleteRequestHeader (const UString &name)
bool deleteTemporaryCookiesFile (Report &report) const
void disableCookies ()
void enableCompression (bool on)
void enableCookies (const fs::path &file_name=fs::path())
bool isInsecure () const
bool isPost () const
bool loadArgs (Args &args)
size_t maxDownloadSize () const
const ByteBlock & postData () const
const UString & proxyHost () const
const UString & proxyPassword () const
uint16_t proxyPort () const
const UString & proxyUser () const
cn::milliseconds receiveTimeout () const
const UStringToUStringMultiMap & requestHeaders () const
UString requestName () const
void setAutoRedirect (bool on)
void setConnectionTimeout (cn::milliseconds timeout)
void setInsecure (bool on)
void setMaxDownloadSize (size_t size)
void setPostData (const ByteBlock &data)
void setPostData (const UString &data, const UString content_type=u"text/plain; charset=utf-8")
void setProxyHost (const UString &host, uint16_t port, bool ignore_empty=false)
void setProxyUser (const UString &user, const UString &password, bool ignore_empty=false)
void setReceiveTimeout (cn::milliseconds timeout)
void setRequestHeader (const UString &name, const UString &value)
void setUserAgent (const UString &name=UString())
const UString & userAgent () const

Static Public Member Functions

static void SetDefaultProxyHost (const UString &host, uint16_t port, bool ignore_empty=false)
static void SetDefaultProxyUser (const UString &user, const UString &password, bool ignore_empty=false)

Static Public Attributes

static constexpr uint16_t DEFAULT_HTTP_PORT = 80
static constexpr uint16_t DEFAULT_HTTPS_PORT = 443
static constexpr const UChar * DEFAULT_USER_AGENT = u"tsduck"

Detailed Description

Command line arguments for the class WebRequest.

Constructor & Destructor Documentation

◆ WebRequestArgs()

ts::WebRequestArgs::WebRequestArgs ( )
default

Constructor.

Member Function Documentation

◆ defineArgs()

void ts::WebRequestArgs::defineArgs ( Args & args)

Add command line option definitions in an Args.

Parameters
[in,out]argsCommand line arguments to update.

◆ loadArgs()

bool ts::WebRequestArgs::loadArgs ( Args & args)

Load arguments from command line. Args error indicator is set in case of incorrect arguments.

Parameters
[in,out]argsCommand line arguments.
Returns
True on success, false on error in argument line.

◆ setConnectionTimeout()

void ts::WebRequestArgs::setConnectionTimeout ( cn::milliseconds timeout)
inline

Set the connection timeout for the request (option --connection-timeout).

Parameters
[in]timeoutConnection timeout in milliseconds.

◆ connectionTimeout()

cn::milliseconds ts::WebRequestArgs::connectionTimeout ( ) const
inline

Get the connection timeout for the request (option --connection-timeout).

Returns
Connection timeout in milliseconds.

◆ setReceiveTimeout()

void ts::WebRequestArgs::setReceiveTimeout ( cn::milliseconds timeout)
inline

Set the timeout for each receive operation (option --receive-timeout).

Parameters
[in]timeoutReception timeout in milliseconds.

◆ receiveTimeout()

cn::milliseconds ts::WebRequestArgs::receiveTimeout ( ) const
inline

Get the timeout for each receive operation (option --receive-timeout).

Returns
Reception timeout in milliseconds.

◆ setProxyHost()

void ts::WebRequestArgs::setProxyHost ( const UString & host,
uint16_t port,
bool ignore_empty = false )

Set the optional proxy host and port for this request (options --proxy-host and --proxy-port).

Parameters
[in]hostProxy host name or address.
[in]portProxy port number.
[in]ignore_emptyIf true, empty host name and zero port number are ignored.

◆ SetDefaultProxyHost()

void ts::WebRequestArgs::SetDefaultProxyHost ( const UString & host,
uint16_t port,
bool ignore_empty = false )
static

Set the default proxy host and port for all subsequent Web requests in the application. Initially loaded from environment variables https_proxy or http_proxy.

Parameters
[in]hostProxy host name or address.
[in]portProxy port number.
[in]ignore_emptyIf true, empty host name and zero port number are ignored.

◆ setProxyUser()

void ts::WebRequestArgs::setProxyUser ( const UString & user,
const UString & password,
bool ignore_empty = false )

Set the optional proxy authentication for this request (options --proxy-user and --proxy-password).

Parameters
[in]userProxy user name.
[in]passwordProxy user's password.
[in]ignore_emptyIf true, empty user name or password are ignored.

◆ SetDefaultProxyUser()

void ts::WebRequestArgs::SetDefaultProxyUser ( const UString & user,
const UString & password,
bool ignore_empty = false )
static

Set the default proxy authentication for all subsequent requests. Initially loaded from environment variables https_proxy or http_proxy.

Parameters
[in]userProxy user name.
[in]passwordProxy user's password.
[in]ignore_emptyIf true, empty user name or password are ignored.

◆ proxyHost()

const UString & ts::WebRequestArgs::proxyHost ( ) const

Get the current actual proxy host (option --proxy-host or default).

Returns
A constant reference to the proxy host name.

◆ proxyPort()

uint16_t ts::WebRequestArgs::proxyPort ( ) const

Get the current actual proxy port number (option --proxy-port or default).

Returns
The proxy port number.

◆ proxyUser()

const UString & ts::WebRequestArgs::proxyUser ( ) const

Get the current actual proxy user name (option --proxy-user or default).

Returns
A constant reference to the proxy user name.

◆ proxyPassword()

const UString & ts::WebRequestArgs::proxyPassword ( ) const

Get the current actual proxy user password (option --proxy-password or default).

Returns
A constant reference to the proxy user password.

◆ setMaxDownloadSize()

void ts::WebRequestArgs::setMaxDownloadSize ( size_t size)
inline

Set a maximum download size. When a download exceeds that size, the transfer is aborted. This limit includes the response headers. The idea is to prevent a hostile server from returnind endless data (or headers). Initially, there is no practical size limit.

Parameters
[in]sizeMaximum download size in bytes.

◆ maxDownloadSize()

size_t ts::WebRequestArgs::maxDownloadSize ( ) const
inline

Get the maximum download size.

Returns
The maximum download size in bytes.
See also
setMaxDownloadSize()

◆ enableCookies()

void ts::WebRequestArgs::enableCookies ( const fs::path & file_name = fs::path())

Enable the propagation of cookies for all requests using the same instance of a web request. Cookies are initially enabled by default.

Parameters
[in]file_nameThe name of the file to use to load and store cookies. On Windows, there is an implicit per-user cookie repository and fileName is ignored. On Unix systems, this file is used to store and retrieve cookies in the libcurl format. When fileName is empty, use a temporary file name.

◆ cookiesEnabled()

bool ts::WebRequestArgs::cookiesEnabled ( ) const
inline

Check if cookies are enabled.

Returns
True if cookies are enabled, false otherwise.

◆ disableCookies()

void ts::WebRequestArgs::disableCookies ( )

Disable the use of cookies for all requests.

◆ cookiesFileName()

const fs::path & ts::WebRequestArgs::cookiesFileName ( ) const
inline

Get the file name to use for cookies for all requests using this instance.

  • On Linux, return the current cookie file name, possibly the name of a temporary file if EnableCookies() was called with an empty string.
  • On Windows, the cookie repository is defined per user. There is no specific per-application file and this method always report an empty string.
    Returns
    A constant reference to the cookie file name.

◆ deleteTemporaryCookiesFile()

bool ts::WebRequestArgs::deleteTemporaryCookiesFile ( Report & report) const

Delete the cookies file, if a temporary one was defined.

Parameters
[in,out]reportWhere to display error messages.
Returns
True on success, false on error.

◆ setUserAgent()

void ts::WebRequestArgs::setUserAgent ( const UString & name = UString())
inline

Set the user agent name to use in HTTP headers (option --user-agent).

Parameters
[in]nameThe user agent name. If empty, DEFAULT_USER_AGENT is used.

◆ userAgent()

const UString & ts::WebRequestArgs::userAgent ( ) const
inline

Get the current user agent name to use in HTTP headers (option --user-agent).

Returns
A constant reference to the user agent name to use in HTTP headers.

◆ enableCompression()

void ts::WebRequestArgs::enableCompression ( bool on)
inline

Enable compression (optoin --compressed). Compression is disabled by default.

Parameters
[in]onBoolean setting compression on or off.

◆ compressionEnabled()

bool ts::WebRequestArgs::compressionEnabled ( ) const
inline

Check if compression is enabled.

Returns
True if compression is enabled.

◆ setInsecure()

void ts::WebRequestArgs::setInsecure ( bool on)
inline

Enable or disable HTTPS security (certificate validation). Certificate validation is enabled by default.

Parameters
[in]onIf true, disable certificate validation.

◆ isInsecure()

bool ts::WebRequestArgs::isInsecure ( ) const
inline

Check if HTTPS security is disabled.

Returns
True if HTTPS security is disabled.

◆ setAutoRedirect()

void ts::WebRequestArgs::setAutoRedirect ( bool on)
inline

Enable or disable the automatic redirection of HTTP requests. Automatic redirection is enabled by default.

Parameters
[in]onIf true, allow automatic redirection of HTTP requests.

◆ autoRedirect()

bool ts::WebRequestArgs::autoRedirect ( ) const
inline

Check if automatic redirection of HTTP requests is enabled.

Returns
True if automatic redirection of HTTP requests is enabled.

◆ setRequestHeader()

void ts::WebRequestArgs::setRequestHeader ( const UString & name,
const UString & value )

Set a header which will be sent with the request (option --headers). If the same header already exists with another value, a new header is added.

Parameters
[in]nameThe header name.
[in]valueThe header value.

◆ deleteRequestHeader()

void ts::WebRequestArgs::deleteRequestHeader ( const UString & name)
inline

Delete all request headers with a given name.

Parameters
[in]nameThe header name.

◆ clearRequestHeaders()

void ts::WebRequestArgs::clearRequestHeaders ( )
inline

Clear all headers which will be sent with the request.

◆ requestHeaders()

const UStringToUStringMultiMap & ts::WebRequestArgs::requestHeaders ( ) const
inline

Get all request headers.

Returns
A constant reference to a map of request headers.

◆ appendRequestHeaders()

void ts::WebRequestArgs::appendRequestHeaders ( UString & text) const

Append all request headers to a text string. Header lines are separated by CR-LF.

Parameters
[in,out]textWhere to append the text lines.

◆ setPostData() [1/2]

void ts::WebRequestArgs::setPostData ( const UString & data,
const UString content_type = u"text/plain; charset=utf-8" )

Set data to POST. The request will be a POST one.

Parameters
[in]dataText POST data. The text will be sent in UTF-8 format.
[in]content_typeThe content type to set in the request headers. The default "Content-Type" header is "text/plain; charset=utf-8", which is usually appropriate. When set to the empty string, no header is set.

◆ setPostData() [2/2]

void ts::WebRequestArgs::setPostData ( const ByteBlock & data)
inline

Set data to POST. The request will be a POST one.

Parameters
[in]dataBinary POST data.

◆ clearPostData()

void ts::WebRequestArgs::clearPostData ( )
inline

Clear previous POST data. The request will be a GET one.

◆ isPost()

bool ts::WebRequestArgs::isPost ( ) const
inline

Check if the request is a POST one.

Returns
True if the request is a POST one.

◆ postData()

const ByteBlock & ts::WebRequestArgs::postData ( ) const
inline

Get the POST data.

Returns
A constant reference to the binary POST data.

◆ requestName()

UString ts::WebRequestArgs::requestName ( ) const
inline

Get the HTTP request name.

Returns
"GET" or "POST".

Member Data Documentation

◆ DEFAULT_HTTP_PORT

uint16_t ts::WebRequestArgs::DEFAULT_HTTP_PORT = 80
staticconstexpr

Default TCP port for HTTP.

◆ DEFAULT_HTTPS_PORT

uint16_t ts::WebRequestArgs::DEFAULT_HTTPS_PORT = 443
staticconstexpr

Default TCP port for HTTPS.

◆ DEFAULT_USER_AGENT

const UChar* ts::WebRequestArgs::DEFAULT_USER_AGENT = u"tsduck"
staticconstexpr

Default user agent string ("tsduck").


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