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