1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QHTTPSERVERWEBSOCKETUPGRADERESPONSE_H
6#define QHTTPSERVERWEBSOCKETUPGRADERESPONSE_H
7
8#include <QtHttpServer/qthttpserverglobal.h>
9
10#include <QtCore/qbytearray.h>
11
12#include <algorithm>
13
14QT_BEGIN_NAMESPACE
15
16class QHttpServerWebSocketUpgradeResponsePrivate;
17class QHttpServerWebSocketUpgradeResponse final
18{
19
20public:
21 Q_HTTPSERVER_EXPORT
22 QHttpServerWebSocketUpgradeResponse(const QHttpServerWebSocketUpgradeResponse &other);
23 QHttpServerWebSocketUpgradeResponse(QHttpServerWebSocketUpgradeResponse &&other) noexcept
24 : responseType(std::move(other.responseType))
25 , errorStatus(std::move(other.errorStatus))
26 , errorMessage(std::move(other.errorMessage))
27 , reserved(std::exchange(obj&: other.reserved, new_val: nullptr))
28 {
29 }
30
31 Q_HTTPSERVER_EXPORT ~QHttpServerWebSocketUpgradeResponse();
32 Q_HTTPSERVER_EXPORT QHttpServerWebSocketUpgradeResponse &
33 operator=(const QHttpServerWebSocketUpgradeResponse &other);
34 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QHttpServerWebSocketUpgradeResponse)
35
36 void swap(QHttpServerWebSocketUpgradeResponse &other) noexcept
37 {
38 std::swap(a&: responseType, b&: other.responseType);
39 std::swap(a&: errorStatus, b&: other.errorStatus);
40 errorMessage.swap(other&: other.errorMessage);
41 std::swap(a&: reserved, b&: other.reserved);
42 }
43
44 enum class ResponseType {
45 Accept,
46 Deny,
47 PassToNext,
48 };
49
50 [[nodiscard]] ResponseType type() const { return responseType; };
51 [[nodiscard]] int denyStatus() const { return errorStatus; }
52 [[nodiscard]] const QByteArray &denyMessage() const & { return errorMessage; }
53 [[nodiscard]] QByteArray denyMessage() && { return std::move(errorMessage); }
54
55 Q_HTTPSERVER_EXPORT static QHttpServerWebSocketUpgradeResponse accept();
56 Q_HTTPSERVER_EXPORT static QHttpServerWebSocketUpgradeResponse deny();
57 Q_HTTPSERVER_EXPORT static QHttpServerWebSocketUpgradeResponse deny(int status,
58 QByteArray message);
59 Q_HTTPSERVER_EXPORT static QHttpServerWebSocketUpgradeResponse passToNext();
60
61private:
62 QHttpServerWebSocketUpgradeResponse() = delete;
63 Q_IMPLICIT QHttpServerWebSocketUpgradeResponse(ResponseType type);
64 QHttpServerWebSocketUpgradeResponse(ResponseType type, int status, QByteArray message);
65
66 ResponseType responseType;
67 int errorStatus = 403;
68 QByteArray errorMessage;
69 void *reserved = nullptr;
70};
71
72Q_DECLARE_SHARED(QHttpServerWebSocketUpgradeResponse)
73
74QT_END_NAMESPACE
75
76#endif // QHTTPSERVERWEBSOCKETUPGRADERESPONSE_H
77

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

source code of qthttpserver/src/httpserver/qhttpserverwebsocketupgraderesponse.h