forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTPRequest.h
More file actions
209 lines (160 loc) · 5.8 KB
/
HTTPRequest.h
File metadata and controls
209 lines (160 loc) · 5.8 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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
//
// HTTPRequest.h
//
// Library: Net
// Package: HTTP
// Module: HTTPRequest
//
// Definition of the HTTPRequest class.
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Net_HTTPRequest_INCLUDED
#define Net_HTTPRequest_INCLUDED
#include "Poco/Net/Net.h"
#include "Poco/Net/HTTPMessage.h"
namespace Poco {
namespace Net {
class Net_API HTTPRequest: public HTTPMessage
/// This class encapsulates an HTTP request
/// message.
///
/// In addition to the properties common to
/// all HTTP messages, a HTTP request has
/// a method (e.g. GET, HEAD, POST, etc.) and
/// a request URI.
{
public:
HTTPRequest();
/// Creates a GET / HTTP/1.0 HTTP request.
explicit HTTPRequest(const std::string& version);
/// Creates a GET / HTTP/1.x request with
/// the given version (HTTP/1.0 or HTTP/1.1).
HTTPRequest(const std::string& method, const std::string& uri);
/// Creates a HTTP/1.0 request with the given method and URI.
HTTPRequest(const std::string& method, const std::string& uri, const std::string& version);
/// Creates a HTTP request with the given method, URI and version.
HTTPRequest(const HTTPRequest& other);
/// Creates a HTTP request by copying another one.
virtual ~HTTPRequest();
/// Destroys the HTTPRequest.
HTTPRequest& operator = (const HTTPRequest&);
/// Assignment operator.
void setMethod(const std::string& method);
/// Sets the method.
const std::string& getMethod() const;
/// Returns the method.
void setURI(const std::string& uri);
/// Sets the request URI.
const std::string& getURI() const;
/// Returns the request URI.
void setHost(const std::string& host);
/// Sets the value of the Host header field.
void setHost(const std::string& host, Poco::UInt16 port);
/// Sets the value of the Host header field.
///
/// If the given port number is a non-standard
/// port number (other than 80 or 443), it is
/// included in the Host header field.
const std::string& getHost() const;
/// Returns the value of the Host header field.
///
/// Throws a NotFoundException if the request
/// does not have a Host header field.
void setCookies(const NameValueCollection& cookies);
/// Adds a Cookie header with the names and
/// values from cookies.
void getCookies(NameValueCollection& cookies) const;
/// Fills cookies with the cookies extracted
/// from the Cookie headers in the request.
bool hasCredentials() const;
/// Returns true iff the request contains authentication
/// information in the form of an Authorization header.
void getCredentials(std::string& scheme, std::string& authInfo) const;
/// Returns the authentication scheme and additional authentication
/// information contained in this request.
///
/// Throws a NotAuthenticatedException if no authentication information
/// is contained in the request.
void setCredentials(const std::string& scheme, const std::string& authInfo);
/// Sets the authentication scheme and information for
/// this request.
void removeCredentials();
/// Removes any credentials from the request.
bool getExpectContinue() const;
/// Returns true if the request contains an
/// "Expect: 100-continue" header.
void setExpectContinue(bool expectContinue);
/// Adds a "Expect: 100-continue" header to the request if
/// expectContinue is true, otherwise removes the Expect header.
bool hasProxyCredentials() const;
/// Returns true iff the request contains proxy authentication
/// information in the form of an Proxy-Authorization header.
void getProxyCredentials(std::string& scheme, std::string& authInfo) const;
/// Returns the proxy authentication scheme and additional proxy authentication
/// information contained in this request.
///
/// Throws a NotAuthenticatedException if no proxy authentication information
/// is contained in the request.
void setProxyCredentials(const std::string& scheme, const std::string& authInfo);
/// Sets the proxy authentication scheme and information for
/// this request.
void removeProxyCredentials();
/// Removes any proxy credentials from the request.
void write(std::ostream& ostr) const;
/// Writes the HTTP request to the given
/// output stream.
void read(std::istream& istr);
/// Reads the HTTP request from the
/// given input stream.
static const std::string HTTP_GET;
static const std::string HTTP_HEAD;
static const std::string HTTP_PUT;
static const std::string HTTP_POST;
static const std::string HTTP_OPTIONS;
static const std::string HTTP_DELETE;
static const std::string HTTP_TRACE;
static const std::string HTTP_CONNECT;
static const std::string HTTP_PATCH;
static const std::string HOST;
static const std::string COOKIE;
static const std::string AUTHORIZATION;
static const std::string PROXY_AUTHORIZATION;
static const std::string UPGRADE;
static const std::string EXPECT;
protected:
void getCredentials(const std::string& header, std::string& scheme, std::string& authInfo) const;
/// Returns the authentication scheme and additional authentication
/// information contained in the given header of request.
///
/// Throws a NotAuthenticatedException if no authentication information
/// is contained in the request.
void setCredentials(const std::string& header, const std::string& scheme, const std::string& authInfo);
/// Writes the authentication scheme and information for
/// this request to the given header.
private:
enum Limits
{
MAX_METHOD_LENGTH = 32,
MAX_URI_LENGTH = 16384,
MAX_VERSION_LENGTH = 8
};
std::string _method;
std::string _uri;
};
//
// inlines
//
inline const std::string& HTTPRequest::getMethod() const
{
return _method;
}
inline const std::string& HTTPRequest::getURI() const
{
return _uri;
}
} } // namespace Poco::Net
#endif // Net_HTTPRequest_INCLUDED