-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathhttprequest.h
More file actions
99 lines (83 loc) · 2.77 KB
/
httprequest.h
File metadata and controls
99 lines (83 loc) · 2.77 KB
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
/*
* Copyright (C) 2012-2016 Fanout, Inc.
* Copyright (C) 2023 Fastly, Inc.
*
* This file is part of Pushpin.
*
* $FANOUT_BEGIN_LICENSE:APACHE2$
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $FANOUT_END_LICENSE$
*/
#ifndef HTTPREQUEST_H
#define HTTPREQUEST_H
#include "url.h"
#include <QHostAddress>
#include "httpheaders.h"
#include <boost/signals2.hpp>
using Signal = boost::signals2::signal<void()>;
using SignalInt = boost::signals2::signal<void(int)>;
class HttpRequest
{
public:
enum ErrorCondition
{
ErrorGeneric,
ErrorPolicy,
ErrorConnect,
ErrorConnectTimeout,
ErrorTls,
ErrorLengthRequired,
ErrorDisconnected,
ErrorTimeout,
ErrorUnavailable,
ErrorRequestTooLarge
};
virtual ~HttpRequest() = default;
virtual QHostAddress peerAddress() const = 0;
virtual void setConnectHost(const QString &host) = 0;
virtual void setConnectPort(int port) = 0;
virtual void setIgnorePolicies(bool on) = 0;
virtual void setTrustConnectHost(bool on) = 0;
virtual void setIgnoreTlsErrors(bool on) = 0;
virtual void setTimeout(int msecs) = 0;
virtual void setClientCert(const QString &cert, const QString &key) = 0;
virtual void start(const QString &method, const Url &uri, const HttpHeaders &headers) = 0;
virtual void beginResponse(int code, const QByteArray &reason, const HttpHeaders &headers) = 0;
// May call this multiple times
virtual void writeBody(const QByteArray &body) = 0;
virtual void endBody() = 0;
virtual int bytesAvailable() const = 0;
virtual int writeBytesAvailable() const = 0;
virtual bool isFinished() const = 0;
virtual bool isInputFinished() const = 0;
virtual bool isOutputFinished() const = 0;
virtual bool isErrored() const = 0;
virtual ErrorCondition errorCondition() const = 0;
virtual QString requestMethod() const = 0;
virtual Url requestUri() const = 0;
virtual HttpHeaders requestHeaders() const = 0;
virtual int responseCode() const = 0;
virtual QByteArray responseReason() const = 0;
virtual HttpHeaders responseHeaders() const = 0;
virtual QByteArray readBody(int size = -1) = 0; // Takes from the buffer
// Indicates input data and/or input finished
Signal readyRead;
// Indicates output data written and/or output finished
SignalInt bytesWritten;
Signal writeBytesChanged;
Signal paused;
Signal error;
};
#endif