QWebSocketCorsAuthenticator Class

The QWebSocketCorsAuthenticator class provides an authenticator object for Cross Origin Requests (CORS). More...

Header: #include <QWebSocketCorsAuthenticator>
CMake: find_package(Qt6 REQUIRED COMPONENTS WebSockets)
target_link_libraries(mytarget PRIVATE Qt6::WebSockets)
qmake: QT += websockets

Public Functions

QWebSocketCorsAuthenticator(const QString &origin)
QWebSocketCorsAuthenticator(const QWebSocketCorsAuthenticator &other)
QWebSocketCorsAuthenticator(QWebSocketCorsAuthenticator &&other)
~QWebSocketCorsAuthenticator()
bool allowed() const
QString origin() const
void setAllowed(bool allowed)
void swap(QWebSocketCorsAuthenticator &other)
QWebSocketCorsAuthenticator &operator=(QWebSocketCorsAuthenticator &&other)
QWebSocketCorsAuthenticator &operator=(const QWebSocketCorsAuthenticator &other)

Detailed Description

The QWebSocketCorsAuthenticator class is used in the originAuthenticationRequired() signal. The class provides a way to pass back the required information to the QWebSocketServer. It provides applications with fine-grained control over which origin URLs are allowed and which aren't. By default, every origin is accepted. To get fine-grained control, an application connects the originAuthenticationRequired() signal to a slot. When the origin (QWebSocketCorsAuthenticator::origin()) is accepted, it calls QWebSocketCorsAuthenticator::setAllowed(true)

Note: Checking on the origin does not make much sense when the server is accessed via a non-browser client, as that client can set whatever origin header it likes. In case of a browser client, the server SHOULD check the validity of the origin.

See also WebSocket Security Considerations and QWebSocketServer.

Member Function Documentation

[explicit] QWebSocketCorsAuthenticator::QWebSocketCorsAuthenticator(const QString &origin)

Constructs a new QCorsAuthencator object with the given origin.

Note: By default, allowed() returns true. This means that per default every origin is accepted.

[explicit] QWebSocketCorsAuthenticator::QWebSocketCorsAuthenticator(const QWebSocketCorsAuthenticator &other)

Constructs a copy of other.

[noexcept] QWebSocketCorsAuthenticator::QWebSocketCorsAuthenticator(QWebSocketCorsAuthenticator &&other)

Move-constructs a QWebSocketCorsAuthenticator, making it point at the same object other was pointing to.

[noexcept] QWebSocketCorsAuthenticator::~QWebSocketCorsAuthenticator()

Destroys the object.

bool QWebSocketCorsAuthenticator::allowed() const

Returns true if the origin is allowed, otherwise returns false.

Note: By default, all origins are accepted.

See also setAllowed().

QString QWebSocketCorsAuthenticator::origin() const

Returns the origin this autenticator is handling about.

void QWebSocketCorsAuthenticator::setAllowed(bool allowed)

Allows or disallows the origin. Setting allowed to true, will accept the connection request for the given origin.

Setting allowed to false, will reject the connection request.

Note: By default, all origins are accepted.

See also allowed().

[noexcept] void QWebSocketCorsAuthenticator::swap(QWebSocketCorsAuthenticator &other)

Swaps other with this authenticator.

This operation is very fast and never fails.

[noexcept] QWebSocketCorsAuthenticator &QWebSocketCorsAuthenticator::operator=(QWebSocketCorsAuthenticator &&other)

Move-assigns other to this instance.

QWebSocketCorsAuthenticator &QWebSocketCorsAuthenticator::operator=(const QWebSocketCorsAuthenticator &other)

Assigns other to this authenticator object.