summaryrefslogtreecommitdiffstats
path: root/src/httpserver/qhttpserverwebsocketupgraderesponse.cpp
blob: 4db7c9c8dd8e18440237cf4bad62037cf4ea2f43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include <QtHttpServer/qhttpserverwebsocketupgraderesponse.h>

#include <QtCore/QString>

QT_BEGIN_NAMESPACE

using namespace Qt::Literals::StringLiterals;

/*!
    \class QHttpServerWebSocketUpgradeResponse
    \since 6.8
    \inmodule QtHttpServer
    \brief Response to return when verifying WebSocket upgrades on HTTP server.

    Use this class to return when determining whether a socket upgrade should
    succeed. If type() is \l Accept upgrade the socket, if type() is \l Deny
    send an error with the given denyStatus() and denyMessage(), and if type()
    is \l PassToNext proceed to the next registered handler.
    If all handlers return \l PassToNext or none exist,
    QAbstractHttpServer::missingHandler() is executed.

    \sa QAbstractHttpServer::addWebSocketUpgradeVerifier(),
    QAbstractHttpServer::missingHandler()
*/

/*!
    \enum QHttpServerWebSocketUpgradeResponse::ResponseType

    Response types

    \value Accept       Accept the WebSocket upgrade request.
    \value Deny         Deny the WebSocket upgrade request.
    \value PassToNext   Pass the Websocket upgrade decision to the next verifier if any.
    \sa QAbstractHttpServer::addWebSocketUpgradeVerifier(), type()
*/

/*!
    \internal
*/
QHttpServerWebSocketUpgradeResponse::QHttpServerWebSocketUpgradeResponse(ResponseType type)
    : responseType(type), errorMessage("Forbidden"_ba), reserved(nullptr)
{
}

/*!
    \internal
*/
QHttpServerWebSocketUpgradeResponse::QHttpServerWebSocketUpgradeResponse(ResponseType type,
                                                                         int status,
                                                                         QByteArray message)
    : responseType(type), errorStatus(status), errorMessage(message), reserved(nullptr)
{
}

/*\fn QHttpServerWebSocketUpgradeResponse::QHttpServerWebSocketUpgradeResponse(QHttpServerWebSocketUpgradeResponse &&other) noexcept

    Move-constructs an instance of a QHttpServerWebSocketUpgradeResponse object from \a other.
*/

/*!
    Copy-constructs an instance of a QHttpServerWebSocketUpgradeResponse object from \a other.
*/
QHttpServerWebSocketUpgradeResponse::QHttpServerWebSocketUpgradeResponse(
        const QHttpServerWebSocketUpgradeResponse &other)
    : responseType(other.responseType),
      errorStatus(other.errorStatus),
      errorMessage(other.errorMessage),
      reserved(nullptr)
{
}

/*!
    Destroys a QHttpServerWebSocketUpgradeResponse object.
*/
QHttpServerWebSocketUpgradeResponse::~QHttpServerWebSocketUpgradeResponse() noexcept = default;

/*!
    \fn QHttpServerWebSocketUpgradeResponse &QHttpServerWebSocketUpgradeResponse::operator=(QHttpServerWebSocketUpgradeResponse &&other) noexcept

    Move-assigns the values of \a other to this object.
*/

/*!
    Copy-assigns the values of \a other to this object.
*/
QHttpServerWebSocketUpgradeResponse &
QHttpServerWebSocketUpgradeResponse::operator=(const QHttpServerWebSocketUpgradeResponse &other)
{
    responseType = other.responseType;
    errorStatus = other.errorStatus;
    errorMessage = other.errorMessage;
    reserved = nullptr;
    return *this;
}

/*!
    \fn void QHttpServerWebSocketUpgradeResponse::swap(QHttpServerWebSocketUpgradeResponse &other) noexcept
    Swaps the contents of this with \a other
*/

/*!
    Creates an instance of QHttpServerWebSocketUpgradeResponse with type()
    \l Accept.

    \sa ResponseType, type()
*/
QHttpServerWebSocketUpgradeResponse QHttpServerWebSocketUpgradeResponse::accept()
{
    return QHttpServerWebSocketUpgradeResponse::ResponseType::Accept;
}

/*!
    Creates an instance of QHttpServerWebSocketUpgradeResponse with
    \l type() \l Deny, \l denyStatus() \c 403 and the \l denyMessage()
    \c "Forbidden".

    \sa ResponseType, type(), denyStatus(), denyMessage()
*/
QHttpServerWebSocketUpgradeResponse QHttpServerWebSocketUpgradeResponse::deny()
{
    return QHttpServerWebSocketUpgradeResponse::ResponseType::Deny;
}

/*!
    Creates an instance of QHttpServerWebSocketUpgradeResponse with type()
    \l Deny, denyStatus() \a status and denyMessage() \a message.

    \sa ResponseType, type(), denyStatus(), denyMessage()
*/
QHttpServerWebSocketUpgradeResponse QHttpServerWebSocketUpgradeResponse::deny(int status,
                                                                        QByteArray message)
{
    return { QHttpServerWebSocketUpgradeResponse::ResponseType::Deny, status, message };
}

/*!
    Creates an instance of QHttpServerWebSocketUpgradeResponse with type() \l PassToNext.

    \sa ResponseType, type()
*/
QHttpServerWebSocketUpgradeResponse QHttpServerWebSocketUpgradeResponse::passToNext()
{
    return QHttpServerWebSocketUpgradeResponse::ResponseType::PassToNext;
}

/*!
    \fn QHttpServerWebSocketUpgradeResponse::ResponseType QHttpServerWebSocketUpgradeResponse::type() const

    Returns the type of response.

    \sa ResponseType
*/

/*!
    \fn int QHttpServerWebSocketUpgradeResponse::denyStatus() const

    Returns the HTTP status code to return if type() is \l Deny.
*/

/*!
    \fn const QByteArray &QHttpServerWebSocketUpgradeResponse::denyMessage() const &

    Returns the error message to return if type() is \l Deny.
*/

/*!
    \fn QByteArray QHttpServerWebSocketUpgradeResponse::denyMessage() &&

    Returns the error message to return if type() is \l Deny.
*/

QT_END_NAMESPACE