QWebSocketCorsAuthenticator Class
QWebSocketCorsAuthenticator 类为跨源请求(CORS)提供了一个验证器对象。更多
Header: | #include <QWebSocketCorsAuthenticator> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS WebSockets) target_link_libraries(mytarget PRIVATE Qt6::WebSockets) |
qmake: | QT += websockets |
公共函数
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) |
详细说明
QWebSocketCorsAuthenticator 类用于originAuthenticationRequired() 信号。该类提供了一种将所需信息传回QWebSocketServer 的方法。它为应用程序提供了细粒度的控制,可以控制哪些起源 URL 被允许,哪些不被允许。默认情况下,每个起源都会被接受。为实现精细控制,应用程序会将originAuthenticationRequired() 信号连接到一个插槽。当起源 (QWebSocketCorsAuthenticator::origin()) 被接受时,它会调用QWebSocketCorsAuthenticator::setAllowed(true)
注意: 通过非浏览器客户端访问服务器时,检查起源没有太大意义,因为该客户端可以设置它喜欢的任何起源头。如果是浏览器客户端,服务器应该检查起源的有效性。
另请参阅 WebSocket 安全注意事项和QWebSocketServer 。
成员函数文档
[explicit]
QWebSocketCorsAuthenticator::QWebSocketCorsAuthenticator(const QString &origin)
使用给定的origin 构建一个新的 QCorsAuthencator 对象。
注: 默认情况下,allowed() 返回 true。这意味着默认情况下,每个原点都会被接受。
[explicit]
QWebSocketCorsAuthenticator::QWebSocketCorsAuthenticator(const QWebSocketCorsAuthenticator &other)
构造other 的副本。
[noexcept]
QWebSocketCorsAuthenticator::QWebSocketCorsAuthenticator(QWebSocketCorsAuthenticator &&other)
移动-创建一个 QWebSocketCorsAuthenticator,使其指向other 所指向的同一对象。
[noexcept]
QWebSocketCorsAuthenticator::~QWebSocketCorsAuthenticator()
销毁对象。
bool QWebSocketCorsAuthenticator::allowed() const
如果允许,则返回 true,否则返回 false。
注: 默认情况下,接受所有来源。
另请参阅 setAllowed().
QString QWebSocketCorsAuthenticator::origin() const
返回该 Autenticator 正在处理的原点。
void QWebSocketCorsAuthenticator::setAllowed(bool allowed)
允许或不允许连接源。将allowed 设置为 true,将接受指定来源的连接请求。
将allowed 设置为 false,将拒绝连接请求。
注: 默认情况下,接受所有来源。
另请参阅 allowed().
[noexcept]
void QWebSocketCorsAuthenticator::swap(QWebSocketCorsAuthenticator &other)
与该验证器交换other 。
这一操作非常快速,从未出现过故障。
[noexcept]
QWebSocketCorsAuthenticator &QWebSocketCorsAuthenticator::operator=(QWebSocketCorsAuthenticator &&other)
Move-assignsother 到此实例。
QWebSocketCorsAuthenticator &QWebSocketCorsAuthenticator::operator=(const QWebSocketCorsAuthenticator &other)
为该身份验证器对象指定other 。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.