WebSession

One isolated browsing context: its own connections, its own cookies (or none), its own cache (or none), and its own identity.

Inherits QObject

Declared in src/libs/libwebrequest/webrequest/WebSession.hpp.

Detailed description

Why this exists

WebRequestManager is a SINGLETON holding one QNetworkAccessManager with one cookie jar and one disk cache, shared by everything in the application that speaks HTTP — the model-catalog fetch, the vendor download, and anything added later. That sharing is right for the app's own services, which talk to hosts the app chose.

It is wrong the moment a URL comes from somewhere the app did not choose. A cookie set while fetching a model catalog would ride along on a page fetched because a document asked for it, and the page would land in a disk cache nobody mentioned. The leak is not hypothetical: one jar plus one arbitrary URL is all it takes.

A session is the fix at the seam rather than at one call site. Any caller that wants isolation makes one, uses it, and destroys it. Nothing is shared with the ambient manager, and nothing survives the destructor unless the caller asked for it.

What it does NOT change

Everything WebRequest already gives you still applies: timeouts, the retry policy with its backoff, the redirect limit, stall detection, TLS identity and the response headers. A session scopes the ambient state; it does not replace the client.

Use

WebSession::Options options;
options.maskUserAgent = true;        // appear as an ordinary browser
WebSession session(QStringLiteral("opal-web-fetch"), options);

WebRequest request(QStringLiteral("fetch"), &session);
request.get(url);
request.waitForFinished();

See also WebRequest, WebRequestManager.

In this section