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

Command line arguments for the class WebRequest. More...

#include <tsWebRequestArgs.h>

Public Member Functions

 WebRequestArgs ()=default
 Constructor.
 
void appendRequestHeaders (UString &text) const
 Append all request headers to a text string.
 
bool autoRedirect () const
 Check if automatic redirection of HTTP requests is enabled.
 
void clearPostData ()
 Clear previous POST data.
 
void clearRequestHeaders ()
 Clear all headers which will be sent with the request.
 
bool compressionEnabled () const
 Check if compression is enabled.
 
cn::milliseconds connectionTimeout () const
 Get the connection timeout for the request (option --connection-timeout).
 
bool cookiesEnabled () const
 Check if cookies are enabled.
 
const fs::path & cookiesFileName () const
 Get the file name to use for cookies for all requests using this instance.
 
void defineArgs (Args &args)
 Add command line option definitions in an Args.
 
void deleteRequestHeader (const UString &name)
 Delete all request headers with a given name.
 
bool deleteTemporaryCookiesFile (Report &report) const
 Delete the cookies file, if a temporary one was defined.
 
void disableCookies ()
 Disable the use of cookies for all requests.
 
void enableCompression (bool on)
 Enable compression (optoin --compressed).
 
void enableCookies (const fs::path &file_name=fs::path())
 Enable the propagation of cookies for all requests using the same instance of a web request.
 
bool isInsecure () const
 Check if HTTPS security is disabled.
 
bool isPost () const
 Check if the request is a POST one.
 
bool loadArgs (Args &args)
 Load arguments from command line.
 
const ByteBlockpostData () const
 Get the POST data.
 
const UStringproxyHost () const
 Get the current actual proxy host (option --proxy-host or default).
 
const UStringproxyPassword () const
 Get the current actual proxy user password (option --proxy-password or default).
 
uint16_t proxyPort () const
 Get the current actual proxy port number (option --proxy-port or default).
 
const UStringproxyUser () const
 Get the current actual proxy user name (option --proxy-user or default).
 
cn::milliseconds receiveTimeout () const
 Get the timeout for each receive operation (option --receive-timeout).
 
const UStringToUStringMultiMaprequestHeaders () const
 Get all request headers.
 
UString requestName () const
 Get the HTTP request name.
 
void setAutoRedirect (bool on)
 Enable or disable the automatic redirection of HTTP requests.
 
void setConnectionTimeout (cn::milliseconds timeout)
 Set the connection timeout for the request (option --connection-timeout).
 
void setInsecure (bool on)
 Enable or disable HTTPS security (certificate validation).
 
void setPostData (const ByteBlock &data)
 Set data to POST.
 
void setPostData (const UString &data, const UString content_type=u"text/plain; charset=utf-8")
 Set data to POST.
 
void setProxyHost (const UString &host, uint16_t port)
 Set the optional proxy host and port for this request (options --proxy-host and --proxy-port).
 
void setProxyUser (const UString &user, const UString &password)
 Set the optional proxy authentication for this request (options --proxy-user and --proxy-password).
 
void setReceiveTimeout (cn::milliseconds timeout)
 Set the timeout for each receive operation (option --receive-timeout).
 
void setRequestHeader (const UString &name, const UString &value)
 Set a header which will be sent with the request (option --headers).
 
void setUserAgent (const UString &name=UString())
 Set the user agent name to use in HTTP headers (option --user-agent).
 
const UStringuserAgent () const
 Get the current user agent name to use in HTTP headers (option --user-agent).
 

Static Public Member Functions

static void SetDefaultProxyHost (const UString &host, uint16_t port)
 Set the default proxy host and port for all subsequent Web requests in the application.
 
static void SetDefaultProxyUser (const UString &user, const UString &password)
 Set the default proxy authentication for all subsequent requests.
 

Static Public Attributes

static constexpr uint16_t DEFAULT_HTTP_PORT = 80
 Default TCP port for HTTP.
 
static constexpr uint16_t DEFAULT_HTTPS_PORT = 443
 Default TCP port for HTTPS.
 
static constexpr const UCharDEFAULT_USER_AGENT = u"tsduck"
 Default user agent string ("tsduck").
 

Detailed Description

Command line arguments for the class WebRequest.

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 
)

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.

◆ SetDefaultProxyHost()

static void ts::WebRequestArgs::SetDefaultProxyHost ( const UString host,
uint16_t  port 
)
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.

◆ setProxyUser()

void ts::WebRequestArgs::setProxyUser ( const UString user,
const UString password 
)

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

Parameters
[in]userProxy user name.
[in]passwordProxy user's password.

◆ SetDefaultProxyUser()

static void ts::WebRequestArgs::SetDefaultProxyUser ( const UString user,
const UString password 
)
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.

◆ 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.

◆ 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.

◆ 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.

◆ 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".

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