![]() |
TSDuck v3.46-4806
MPEG Transport Stream Toolkit
|
Perform a simple Web request (HTTP, HTTPS, FTP). More...
#include <tsWebRequest.h>


Public Member Functions | |
| WebRequest (Report *report) | |
| Constructor. | |
| WebRequest (ReporterBase *delegate) | |
| Constructor. | |
| virtual | ~WebRequest () override |
| Destructor. | |
| void | abort () |
| Abort a transfer in progress. | |
| WebRequestArgs & | args () |
| Access the Web request arguments to get or set them. | |
| const WebRequestArgs & | args () const |
| Access the Web request arguments to get them. | |
| bool | close () |
| Close the transfer. | |
| bool | downloadBinaryContent (const UString &url, ByteBlockPtr &data, size_t chunk_size=Device::DEFAULT_RECEIVE_BUFFER_SIZE) |
| Download the content of the URL as binary data in one operation. | |
| bool | downloadFile (const UString &url, const fs::path &file_name, size_t chunk_size=Device::DEFAULT_RECEIVE_BUFFER_SIZE) |
| Download the content of the URL in a file in one operation. | |
| bool | downloadTextContent (const UString &url, UString &text, size_t chunk_size=Device::DEFAULT_RECEIVE_BUFFER_SIZE) |
| Download the content of the URL as text in one operation. | |
| bool | isOpen () const |
| Check if a transfer is open. | |
| bool | muteReport (bool mute) |
| Temporarily mute the associated report. | |
| bool | open (const UString &url, size_t buffer_size=Device::DEFAULT_RECEIVE_BUFFER_SIZE) |
| Open an URL and start the transfer. | |
| bool | receive (void *buffer, size_t max_size, size_t &ret_size) |
| Receive data. | |
| virtual Report & | report () const override |
| Access the Report which is associated with this object. | |
| Report * | setReport (Report *report) |
| Associate this object with another Report to log errors. | |
| ReporterBase * | setReport (ReporterBase *delegate) |
| Associate this object with another ReporterBase to log errors. | |
| const WebRequestStatus & | status () const |
| Access the Web request status. | |
Static Public Member Functions | |
| static int | SilentLevel (bool silent, int default_severity=Severity::Error) |
| Compute a log severity level from a "silent" parameter. | |
Perform a simple Web request (HTTP, HTTPS, FTP).
On UNIX systems, the implementation uses libcurl. On Windows systems, the implementation uses Microsoft Wininet. We could have used libcurl on Windows but building it was a pain...
The proxy and transfer settings must be set before starting any download operation. The HTTP status and the response headers are available after a successful download start.
By default, no proxy is used. If no proxy is set, the default proxy is used (system configuration on Windows, http_proxy environment on Unix systems).
|
explicit |
Constructor.
| [in] | report | Where to report errors. The report object must remain valid as long as this object exists or setReport() is used with another Report object. If report is null, log messages are discarded. |
|
explicit |
Constructor.
| [in] | delegate | Use the report of another ReporterBase. If delegate is null, log messages are discarded. |
| WebRequestArgs & ts::WebRequest::args | ( | ) |
Access the Web request arguments to get or set them.
| const WebRequestArgs & ts::WebRequest::args | ( | ) | const |
Access the Web request arguments to get them.
| const WebRequestStatus & ts::WebRequest::status | ( | ) | const |
Access the Web request status.
| bool ts::WebRequest::open | ( | const UString & | url, |
| size_t | buffer_size = Device::DEFAULT_RECEIVE_BUFFER_SIZE |
||
| ) |
| bool ts::WebRequest::isOpen | ( | ) | const |
Check if a transfer is open.
| bool ts::WebRequest::receive | ( | void * | buffer, |
| size_t | max_size, | ||
| size_t & | ret_size | ||
| ) |
Receive data.
| [out] | buffer | Address of the buffer for the received data. |
| [in] | max_size | Size in bytes of the reception buffer. |
| [out] | ret_size | Size in bytes of the received data. Will never be larger than max_size. When ret_size is zero, this is the end of the transfer. |
| bool ts::WebRequest::close | ( | ) |
Close the transfer.
| void ts::WebRequest::abort | ( | ) |
Abort a transfer in progress.
Can be called from another thread.
| bool ts::WebRequest::downloadBinaryContent | ( | const UString & | url, |
| ByteBlockPtr & | data, | ||
| size_t | chunk_size = Device::DEFAULT_RECEIVE_BUFFER_SIZE |
||
| ) |
Download the content of the URL as binary data in one operation.
The open/read/close session is embedded in this method. The request must be in blocking mode (the default).
| [in] | url | The complete URL to fetch. |
| [out] | data | The content of the URL in a shred pointer. Null in case of error. |
| [in] | chunk_size | Individual download chunk size. |
| bool ts::WebRequest::downloadTextContent | ( | const UString & | url, |
| UString & | text, | ||
| size_t | chunk_size = Device::DEFAULT_RECEIVE_BUFFER_SIZE |
||
| ) |
Download the content of the URL as text in one operation.
The open/read/close session is embedded in this method.. The downloaded text is converted from UTF-8. End of lines are normalized as LF. The request must be in blocking mode (the default).
| [in] | url | The complete URL to fetch. |
| [out] | text | The content of the URL. |
| [in] | chunk_size | Individual download chunk size. |
| bool ts::WebRequest::downloadFile | ( | const UString & | url, |
| const fs::path & | file_name, | ||
| size_t | chunk_size = Device::DEFAULT_RECEIVE_BUFFER_SIZE |
||
| ) |
Download the content of the URL in a file in one operation.
The open/read/close session is embedded in this method.. No transformation is applied to the data. The request must be in blocking mode (the default).
| [in] | url | The complete URL to fetch. |
| [in] | file_name | Name of the file to create. |
| [in] | chunk_size | Individual download chunk size. |
|
overridevirtualinherited |
Access the Report which is associated with this object.
Can be called from another thread only if the Report object is thread-safe.
Implements ts::ReporterInterface.
Associate this object with another Report to log errors.
| [in] | report | Where to report errors. The report object must remain valid as long as this object exists or setReport() is used with another Report object. If report is null, log messages are discarded. |
|
inherited |
Associate this object with another ReporterBase to log errors.
| [in] | delegate | Use the report of another ReporterBase. If delegate is null, the previous explicit Report is used.. |
|
inherited |
Temporarily mute the associated report.
| [in] | mute | It true, report() will return a null report (log messages are discarded), until muteReport() is invoked again with mute set to false. |
|
inlinestaticinherited |
Compute a log severity level from a "silent" parameter.
Some subclass methods have a "silent" parameter to avoid reporting errors which may be insignificant, typically when closing a device after an error, in which case the close operation may produce other errors if the previous error left the device in an inconsistent state. While those errors should not be displayed as errors, we still display them at debug level.
| [in] | silent | If true, do not report errors, report debug messages instead. |
| [in] | default_severity | Default severity, in non-silent mode (error by default). |