1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QHTTPSERVERRESPONSE_H
5#define QHTTPSERVERRESPONSE_H
6
7#include <QtHttpServer/qhttpserverresponder.h>
8
9#include <memory>
10
11QT_BEGIN_NAMESPACE
12
13class QJsonObject;
14
15class QHttpServerResponsePrivate;
16class Q_HTTPSERVER_EXPORT QHttpServerResponse final
17{
18 Q_DECLARE_PRIVATE(QHttpServerResponse)
19 Q_DISABLE_COPY(QHttpServerResponse)
20
21 friend class QHttpServerResponder;
22public:
23 using StatusCode = QHttpServerResponder::StatusCode;
24
25 QHttpServerResponse(QHttpServerResponse &&other) noexcept;
26 QHttpServerResponse& operator=(QHttpServerResponse &&other) noexcept;
27
28 QHttpServerResponse(const StatusCode statusCode);
29
30 QHttpServerResponse(const char *data, const StatusCode status = StatusCode::Ok);
31
32 QHttpServerResponse(const QString &data, const StatusCode status = StatusCode::Ok);
33
34 explicit QHttpServerResponse(const QByteArray &data, const StatusCode status = StatusCode::Ok);
35 explicit QHttpServerResponse(QByteArray &&data, const StatusCode status = StatusCode::Ok);
36
37 QHttpServerResponse(const QJsonObject &data, const StatusCode status = StatusCode::Ok);
38 QHttpServerResponse(const QJsonArray &data, const StatusCode status = StatusCode::Ok);
39
40 QHttpServerResponse(const QByteArray &mimeType,
41 const QByteArray &data,
42 const StatusCode status = StatusCode::Ok);
43 QHttpServerResponse(QByteArray &&mimeType,
44 const QByteArray &data,
45 const StatusCode status = StatusCode::Ok);
46 QHttpServerResponse(const QByteArray &mimeType,
47 QByteArray &&data,
48 const StatusCode status = StatusCode::Ok);
49 QHttpServerResponse(QByteArray &&mimeType,
50 QByteArray &&data,
51 const StatusCode status = StatusCode::Ok);
52
53 ~QHttpServerResponse();
54 static QHttpServerResponse fromFile(const QString &fileName);
55
56 QByteArray data() const;
57
58 QByteArray mimeType() const;
59
60 StatusCode statusCode() const;
61
62 void addHeader(QByteArray &&name, QByteArray &&value);
63 void addHeader(QByteArray &&name, const QByteArray &value);
64 void addHeader(const QByteArray &name, QByteArray &&value);
65 void addHeader(const QByteArray &name, const QByteArray &value);
66
67 void addHeaders(QHttpServerResponder::HeaderList headers);
68
69 template<typename Container>
70 void addHeaders(const Container &headerList)
71 {
72 for (const auto &header : headerList)
73 addHeader(header.first, header.second);
74 }
75
76 void clearHeader(const QByteArray &name);
77 void clearHeaders();
78
79 void setHeader(QByteArray &&name, QByteArray &&value);
80 void setHeader(QByteArray &&name, const QByteArray &value);
81 void setHeader(const QByteArray &name, QByteArray &&value);
82 void setHeader(const QByteArray &name, const QByteArray &value);
83
84 void setHeaders(QHttpServerResponder::HeaderList headers);
85
86 bool hasHeader(const QByteArray &name) const;
87 bool hasHeader(const QByteArray &name, const QByteArray &value) const;
88
89 QList<QByteArray> headers(const QByteArray &name) const;
90
91private:
92 std::unique_ptr<QHttpServerResponsePrivate> d_ptr;
93};
94
95QT_END_NAMESPACE
96
97#endif // QHTTPSERVERRESPONSE_H
98

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