HttpClient.h header

#include <ew/app/HttpClient.h>

Namespace ew::app

HttpClient class

class ew::app::HttpClient

Fetches bytes over HTTP. An interface so libs/app and the UI can express "download this" without depending on a network stack (docs/LOCAL_ENGINEERING_RUN.md section 4.1) – the implementation lives in libs/cloud, the only module that has one.

Members

ew::app::net::HttpClient::HttpClient()=default

Defaulted.

virtual ew::app::net::HttpClient::~HttpClient()=default

Defaulted.

ew::app::net::HttpClient::HttpClient(const HttpClient &)=delete

Interface type: non-copyable and non-movable (held via pointer).

ew::app::net::HttpClient::HttpClient(HttpClient &&)=delete

Not movable.

HttpClient & ew::app::net::HttpClient::operator=(const HttpClient &)=delete

Not copyable.

HttpClient & ew::app::net::HttpClient::operator=(HttpClient &&)=delete

Not movable.

virtual std::unique_ptr< HttpRequest > ew::app::net::HttpClient::get(const QString &url, std::function< void(HttpResult)> onFinished, std::function< void(qint64 received, qint64 total)> onProgress={})=0

GETs url, calling onFinished when it ends and onProgress (when supplied) as bytes arrive. Asynchronous: it returns immediately and the callbacks run on the calling thread's event loop, which is what lets the caller stay a UI object without blocking.

onProgress receives bytes-received and bytes-total, where total is -1 while the server has not said. Returns the handle; letting it go out of scope cancels the request.

virtual std::unique_ptr< HttpRequest > ew::app::net::HttpClient::post(const QString &url, const QString &contentType, const QByteArray &body, std::function< void(HttpResult)> onFinished)=0

POSTs body to url with content type contentType, calling onFinished when it ends. Asynchronous on the same terms as get().

Separate from get() rather than a verb parameter, because the two differ in what the caller must supply: a POST has a body and a content type and a GET has neither, and folding them together would make every GET caller pass two empty arguments to say "not applicable".

There is no progress callback: the payloads this exists for – a webhook notification, an API call – are small enough that progress is noise, and an upload nobody is watching does not need one. Returns the handle; letting it go out of scope cancels the request.

HttpRequest class

class ew::app::HttpRequest

A request already in flight. Destroying the handle cancels it, so a caller that drops the handle cannot leave a request running against an object that has gone away.

Members

ew::app::net::HttpRequest::HttpRequest()=default

Defaulted.

virtual ew::app::net::HttpRequest::~HttpRequest()=default

Cancels the request if it is still running.

ew::app::net::HttpRequest::HttpRequest(const HttpRequest &)=delete

Interface type: non-copyable and non-movable (held via pointer).

ew::app::net::HttpRequest::HttpRequest(HttpRequest &&)=delete

Not movable.

HttpRequest & ew::app::net::HttpRequest::operator=(const HttpRequest &)=delete

Not copyable.

HttpRequest & ew::app::net::HttpRequest::operator=(HttpRequest &&)=delete

Not movable.

virtual void ew::app::net::HttpRequest::cancel()=0

Aborts the request. The completion callback still runs, with HttpResult::cancelled set.

HttpResult struct

struct ew::app::HttpResult

How a request ended.

Members

bool ew::app::net::HttpResult::ok = false

True when the body arrived intact.

QByteArray ew::app::net::HttpResult::body

The response body, when ok.

QString ew::app::net::HttpResult::error

A human-readable failure message, when not ok.

bool ew::app::net::HttpResult::cancelled = false

True when the caller cancelled it rather than it failing. Kept separate from error because a cancelled download is not something to report to the user as a problem – they already know, having asked for it.

Functions

std::unique_ptr< HttpClient > ew::app::net::makeHttpClient()

Builds the HTTP client this build ships with, or null when it ships none.

The same seam as ew::app::ai::makeAiProvider, and the same two definitions: libs/cloud when EW_ENABLE_CLOUD is on, libs/app/src/net/NoCloudHttpClient.cpp when it is off.

Null here, unlike the AI provider, is the honest answer. An AI provider that reports itself unconfigured is a state the UI already renders; a fetch has no equivalent – there is nothing meaningful to hand back but "this build cannot". Callers check once, at the point they would have started a request, and simply do not offer the feature.