AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
ACurl Class Reference

Easy curl instance. More...

Detailed Description

Easy curl instance.

ACurl::Builder is used to construct ACurl.

Analogous to Qt's QNetworkRequest.

Classes

class  Builder
 
struct  ErrorDescription
 
class  Exception
 
struct  Response
 Response struct for Builder::runBlocking() and Builder::runAsync() More...
 

Public Types

enum class  Http {
  VERSION_NONE , VERSION_1_0 , VERSION_1_1 , VERSION_2_0 ,
  VERSION_2TLS , VERSION_2_PRIOR_KNOWLEDGE , VERSION_3 = 30 , VERSION_LAST
}
 
enum class  ResponseCode {
  HTTP_100_CONTINUE = 100 , HTTP_101_SWITCHING_PROTOCOL = 101 , HTTP_102_PROCESSING = 102 , HTTP_103_EARLY_HINTS = 103 ,
  HTTP_200_OK = 200 , HTTP_201_CREATED = 201 , HTTP_202_ACCEPTED = 202 , HTTP_203_NON_AUTHORITATIVE_INFORMATION = 203 ,
  HTTP_204_NO_CONTENT = 204 , HTTP_205_RESET_CONTENT = 205 , HTTP_206_PARTIAL_CONTENT = 206 , HTTP_300_MULTIPLE_CHOICE = 300 ,
  HTTP_301_MOVED_PERMANENTLY = 301 , HTTP_302_FOUND = 302 , HTTP_303_SEE_OTHER = 303 , HTTP_304_NOT_MODIFIED = 304 ,
  HTTP_305_USE_PROXY = 305 , HTTP_306_SWITCH_PROXY = 306 , HTTP_307_TEMPORARY_REDIRECT = 307 , HTTP_308_PERMANENT_REDIRECT = 308 ,
  HTTP_400_BAD_REQUEST = 400 , HTTP_401_UNAUTHORIZED = 401 , HTTP_402_PAYMENT_REQUIRED = 402 , HTTP_403_FORBIDDEN = 403 ,
  HTTP_404_NOT_FOUND = 404 , HTTP_405_METHOD_NOT_ALLOWED = 405 , HTTP_406_NOT_ACCEPTABLE = 406 , HTTP_407_PROXY_AUTHENTICATION_REQUIRED = 407 ,
  HTTP_408_REQUEST_TIMEOUT = 408 , HTTP_409_CONFLICT = 409 , HTTP_410_GONE = 410 , HTTP_411_LENGTH_REQUIRED = 411 ,
  HTTP_412_PRECONDITION_FAILED = 412 , HTTP_413_REQUEST_ENTITY_TOO_LARGE = 413 , HTTP_414_REQUEST_URI_TOO_LONG = 414 , HTTP_415_UNSUPPORTED_MEDIA_TYPE = 415 ,
  HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE = 416 , HTTP_417_EXPECTATION_FAILED = 417 , HTTP_500_INTERNAL_SERVER_ERROR = 500 , HTTP_501_NOT_IMPLEMENTED = 501 ,
  HTTP_502_BAD_GATEWAY = 502 , HTTP_503_SERVICE_UNAVAILABLE = 503 , HTTP_504_GATEWAY_TIMEOUT = 504 , HTTP_505_HTTP_VERSION_NOT_SUPPORTED = 505
}
 
enum class  Method { HTTP_GET , HTTP_POST , HTTP_PUT , HTTP_DELETE }
 
using WriteCallback = std::function< size_t(AByteBufferView data)>
 A read callback. More...
 
using ReadCallback = std::function< std::size_t(char *dst, size_t maxLen)>
 A read callback. More...
 
using HeaderCallback = std::function< void(AByteBufferView)>
 
using ErrorCallback = std::function< void(const ErrorDescription &description)>
 

Public Member Functions

 ACurl (Builder &builder)
 
 ACurl (Builder &&builder) noexcept
 
 ACurl (ACurl &&o) noexcept
 
ACurloperator= (Builder &&o) noexcept
 
ACurloperator= (ACurl &&o) noexcept
 
int64_t getContentLength () const
 
int64_t getNumberOfBytesDownloaded () const
 
AString getContentType () const
 
void run ()
 
virtual void close ()
 Breaks curl loop in the run() method, closing underlying curl connection. More...
 
void * handle () const noexcept
 
ResponseCode getResponseCode () const
 
AString getErrorString () const noexcept
 
- Public Member Functions inherited from AObject
_< AObjectsharedPtr ()
 
_weak< AObjectweakPtr ()
 
void clearSignals () noexcept
 
template<AAnySignal Signal, ACompatibleSlotFor< Signal > Function>
void connect (Signal &signal, Function &&function)
 
void setSignalsEnabled (bool enabled)
 
bool isSignalsEnabled () const noexcept
 
template<ASignalInvokable T>
void operator^ (T &&t)
 
_< AAbstractThreadgetThread () const
 
bool isSlotsCallsOnlyOnMyThread () const noexcept
 
void setSlotsCallsOnlyOnMyThread (bool slotsCallsOnlyOnMyThread)
 
- Public Member Functions inherited from aui::noncopyable
 noncopyable (const noncopyable &)=delete
 
noncopyableoperator= (const noncopyable &)=delete
 

Signals and public fields

emits< ErrorDescriptionfail
 Emitted on network error. More...
 
emits success
 Emitted on success. More...
 
emits closeRequested
 

Friends

class ACurlMulti
 

Additional Inherited Members

- Static Public Member Functions inherited from AObject
static void disconnect ()
 
template<AAnySignal Signal, aui::derived_from< AObject > Object, ACompatibleSlotFor< Signal > Function>
static void connect (Signal &signal, Object *object, Function &&function)
 
template<AAnySignal Signal, aui::derived_from< AObject > Object, ACompatibleSlotFor< Signal > Function>
static void connect (Signal &signal, Object &object, Function &&function)
 
template<AAnySignal Signal, aui::derived_from< AObject > Object, ACompatibleSlotFor< Signal > Function>
static void connect (Signal &signal, _< Object > object, Function &&function)
 
static void moveToThread (aui::no_escape< AObject > object, _< AAbstractThread > thread)
 
- Protected Member Functions inherited from AObject
void setThread (_< AAbstractThread > thread)
 Set thread of the object.
 

Member Typedef Documentation

◆ ReadCallback

using ACurl::ReadCallback = std::function<std::size_t(char* dst, size_t maxLen)>

A read callback.

Parameters
dstdestination buffer you should write to.
maxLendestination buffer size aka max length.
Returns
bytes written to the destination buffer. Zero means data unavailability (but the stream may be continued in the future).

Unlike regular streams, blocking is not allowed. To indicate the data unavailability, return zero. To indicate end of file, throw an AEOFException.

◆ WriteCallback

using ACurl::WriteCallback = std::function<size_t(AByteBufferView data)>

A read callback.

Parameters
datareceived data
Returns
bytes written to the destination buffer. Zero means buffer does not have enough space to store supplied data (but the stream may be continued in the future), the supplied data is not discarded and being kept in the curl buffers.

Unlike regular streams, blocking is not allowed. To indicate buffer overflow, return zero. To indicate end of file, throw an AEOFException.

Member Function Documentation

◆ close()

void ACurl::close ( )
virtual

Breaks curl loop in the run() method, closing underlying curl connection.

curl does not have a function which immediately stops the transfer (see https://curl.se/docs/faq.html#How_do_I_stop_an_ongoing_transfe). The stop functionality is handled in ACurl by returning error code on all callbacks. close() function is non-blocking, and some time would be taken until the run() method finally returns.

After calling close() method, none of the result signals (like fail, success) will be called.

close() is non-blocking function.

close() is thread-safe.

Reimplemented in AWebsocket.

Member Data Documentation

◆ fail

emits<ErrorDescription> ACurl::fail

Emitted on network error.

Note
A protocol-level error (like HTTP(S) 404) is not treated as a fail. Check for response code via the getResponseCode() function.

◆ success

emits ACurl::success

Emitted on success.

Note
A protocol-level error (like HTTP(S) 404) is not treated as a fail. Check for response code via the getResponseCode() function.

#include <AUI/Curl/ACurl.h>


The documentation for this class was generated from the following files:
Inheritance diagram for ACurl:
Collaboration diagram for ACurl: