AWS SDK for C++  1.8.95
AWS SDK for C++
HttpRequest.h
Go to the documentation of this file.
1 
6 #pragma once
7 
9 
10 #include <aws/core/http/URI.h>
16 #include <memory>
17 #include <functional>
18 
19 namespace Aws
20 {
21  namespace Http
22  {
23  extern AWS_CORE_API const char DATE_HEADER[];
24  extern AWS_CORE_API const char AWS_DATE_HEADER[];
25  extern AWS_CORE_API const char AWS_SECURITY_TOKEN[];
26  extern AWS_CORE_API const char ACCEPT_HEADER[];
27  extern AWS_CORE_API const char ACCEPT_CHAR_SET_HEADER[];
28  extern AWS_CORE_API const char ACCEPT_ENCODING_HEADER[];
29  extern AWS_CORE_API const char AUTHORIZATION_HEADER[];
30  extern AWS_CORE_API const char AWS_AUTHORIZATION_HEADER[];
31  extern AWS_CORE_API const char COOKIE_HEADER[];
32  extern AWS_CORE_API const char CONTENT_LENGTH_HEADER[];
33  extern AWS_CORE_API const char CONTENT_TYPE_HEADER[];
34  extern AWS_CORE_API const char TRANSFER_ENCODING_HEADER[];
35  extern AWS_CORE_API const char USER_AGENT_HEADER[];
36  extern AWS_CORE_API const char VIA_HEADER[];
37  extern AWS_CORE_API const char HOST_HEADER[];
38  extern AWS_CORE_API const char AMZ_TARGET_HEADER[];
39  extern AWS_CORE_API const char X_AMZ_EXPIRES_HEADER[];
40  extern AWS_CORE_API const char CONTENT_MD5_HEADER[];
41  extern AWS_CORE_API const char API_VERSION_HEADER[];
42  extern AWS_CORE_API const char SDK_INVOCATION_ID_HEADER[];
43  extern AWS_CORE_API const char SDK_REQUEST_HEADER[];
44  extern AWS_CORE_API const char CHUNKED_VALUE[];
45 
46  class HttpRequest;
47  class HttpResponse;
48 
52  typedef std::function<void(const HttpRequest*, HttpResponse*, long long)> DataReceivedEventHandler;
56  typedef std::function<void(const HttpRequest*, long long)> DataSentEventHandler;
60  typedef std::function<bool(const HttpRequest*)> ContinueRequestHandler;
61 
66  {
67  public:
71  HttpRequest(const URI& uri, HttpMethod method) :
72  m_uri(uri), m_method(method), m_isEvenStreamRequest(false)
73  {}
74 
75  virtual ~HttpRequest() {}
76 
80  virtual HeaderValueCollection GetHeaders() const = 0;
84  virtual const Aws::String& GetHeaderValue(const char* headerName) const = 0;
88  virtual void SetHeaderValue(const char* headerName, const Aws::String& headerValue) = 0;
92  virtual void SetHeaderValue(const Aws::String& headerName, const Aws::String& headerValue) = 0;
96  virtual void DeleteHeader(const char* headerName) = 0;
100  virtual void AddContentBody(const std::shared_ptr<Aws::IOStream>& strContent) = 0;
104  virtual const std::shared_ptr<Aws::IOStream>& GetContentBody() const = 0;
108  virtual bool HasHeader(const char* name) const = 0;
112  virtual int64_t GetSize() const = 0;
116  virtual const Aws::IOStreamFactory& GetResponseStreamFactory() const = 0;
120  virtual void SetResponseStreamFactory(const Aws::IOStreamFactory& factory) = 0;
124  inline URI& GetUri()
125  {
126  return m_uri;
127  }
131  const URI& GetUri() const { return m_uri; }
136  inline Aws::String GetURIString(bool includeQueryString = true) const
137  {
138  return m_uri.GetURIString(includeQueryString);
139  }
143  inline HttpMethod GetMethod() const
144  {
145  return m_method;
146  }
150  inline const Aws::String& GetQueryString() const
151  {
152  return m_uri.GetQueryString();
153  }
157  inline void CanonicalizeRequest()
158  {
159  m_uri.CanonicalizeQueryString();
160  }
165  {
166  return m_uri.GetQueryStringParameters();
167  }
171  inline void AddQueryStringParameter(const char* key, const Aws::String& value)
172  {
173  m_uri.AddQueryStringParameter(key, value);
174  }
175 
176  inline bool HasDate() const
177  {
178  return HasHeader(DATE_HEADER);
179  }
183  inline const Aws::String& GetDate() const
184  {
185  return GetHeaderValue(DATE_HEADER);
186  }
190  inline void SetDate(const Aws::String& value)
191  {
192  SetHeaderValue(DATE_HEADER, value);
193  }
194 
195  inline bool HasAccept() const
196  {
197  return HasHeader(ACCEPT_HEADER);
198  }
202  inline const Aws::String& GetAccept() const
203  {
204  return GetHeaderValue(ACCEPT_HEADER);
205  }
209  inline void SetAccept(const Aws::String& value)
210  {
211  SetHeaderValue(ACCEPT_HEADER, value);
212  }
213 
214  inline bool HasAcceptCharSet() const
215  {
216  return HasHeader(ACCEPT_CHAR_SET_HEADER);
217  }
221  inline const Aws::String& GetAcceptCharSet() const
222  {
223  return GetHeaderValue(ACCEPT_CHAR_SET_HEADER);
224  }
228  inline void SetAcceptCharSet(const Aws::String& value)
229  {
230  SetHeaderValue(ACCEPT_CHAR_SET_HEADER, value);
231  }
232 
233  inline bool HasAcceptEncoding() const
234  {
235  return HasHeader(ACCEPT_ENCODING_HEADER);
236  }
240  inline const Aws::String& GetAcceptEncoding() const
241  {
242  return GetHeaderValue(ACCEPT_ENCODING_HEADER);
243  }
247  inline void SetAcceptEncoding(const Aws::String& value)
248  {
249  SetHeaderValue(ACCEPT_ENCODING_HEADER, value);
250  }
251 
252  inline bool HasAuthorization() const
253  {
254  return HasHeader(AUTHORIZATION_HEADER);
255  }
259  inline const Aws::String& GetAuthorization() const
260  {
261  return GetHeaderValue(AUTHORIZATION_HEADER);
262  }
266  inline void SetAuthorization(const Aws::String& value)
267  {
268  SetHeaderValue(AUTHORIZATION_HEADER, value);
269  }
270 
271  inline bool HasAwsAuthorization() const
272  {
273  return HasHeader(AWS_AUTHORIZATION_HEADER);
274  }
278  inline const Aws::String& GetAwsAuthorization() const
279  {
280  return GetHeaderValue(AWS_AUTHORIZATION_HEADER);
281  }
285  inline void SetAwsAuthorization(const Aws::String& value)
286  {
287  SetHeaderValue(AWS_AUTHORIZATION_HEADER, value);
288  }
289 
290  inline bool HasAwsSessionToken() const
291  {
292  return HasHeader(AWS_SECURITY_TOKEN);
293  }
297  inline const Aws::String& GetAwsSessionToken() const
298  {
299  return GetHeaderValue(AWS_SECURITY_TOKEN);
300  }
304  inline void SetAwsSessionToken(const Aws::String& value)
305  {
306  SetHeaderValue(AWS_SECURITY_TOKEN, value);
307  }
308 
309  inline bool HasCookie() const
310  {
311  return HasHeader(COOKIE_HEADER);
312  }
316  inline const Aws::String& GetCookie() const
317  {
318  return GetHeaderValue(COOKIE_HEADER);
319  }
323  inline void SetCookie(const Aws::String& value)
324  {
325  SetHeaderValue(COOKIE_HEADER, value);
326  }
327 
328  inline bool HasContentLength() const
329  {
330  return HasHeader(CONTENT_LENGTH_HEADER);
331  }
335  inline const Aws::String& GetContentLength() const
336  {
337  return GetHeaderValue(CONTENT_LENGTH_HEADER);
338  }
342  inline void SetContentLength(const Aws::String& value)
343  {
344  SetHeaderValue(CONTENT_LENGTH_HEADER, value);
345  }
346 
347  inline bool HasContentType() const
348  {
349  return HasHeader(CONTENT_TYPE_HEADER);
350  }
354  inline const Aws::String& GetContentType() const
355  {
356  return GetHeaderValue(CONTENT_TYPE_HEADER);
357  }
361  inline void SetContentType(const Aws::String& value)
362  {
363  SetHeaderValue(CONTENT_TYPE_HEADER, value);
364  }
365 
366  inline bool HasTransferEncoding() const
367  {
368  return HasHeader(TRANSFER_ENCODING_HEADER);
369  }
373  inline const Aws::String& GetTransferEncoding() const
374  {
375  return GetHeaderValue(TRANSFER_ENCODING_HEADER);
376  }
380  inline void SetTransferEncoding(const Aws::String& value)
381  {
382  SetHeaderValue(TRANSFER_ENCODING_HEADER, value);
383  }
384 
385  inline bool HasUserAgent() const
386  {
387  return HasHeader(USER_AGENT_HEADER);
388  }
392  inline const Aws::String& GetUserAgent() const
393  {
394  return GetHeaderValue(USER_AGENT_HEADER);
395  }
399  inline void SetUserAgent(const Aws::String& value)
400  {
401  SetHeaderValue(USER_AGENT_HEADER, value);
402  }
403 
404  inline bool HasVia() const
405  {
406  return HasHeader(VIA_HEADER);
407  }
411  inline const Aws::String& GetVia() const
412  {
413  return GetHeaderValue(VIA_HEADER);
414  }
418  inline void SetVia(const Aws::String& value)
419  {
420  SetHeaderValue(VIA_HEADER, value);
421  }
422 
426  inline bool HasApiVersion() const
427  {
428  return HasHeader(API_VERSION_HEADER);
429  }
430 
434  inline const Aws::String& GetApiVersion() const
435  {
436  return GetHeaderValue(API_VERSION_HEADER);
437  }
441  inline void SetApiVersion(const Aws::String& value)
442  {
443  SetHeaderValue(API_VERSION_HEADER, value);
444  }
445 
449  inline void SetDataReceivedEventHandler(const DataReceivedEventHandler& dataReceivedEventHandler) { m_onDataReceived = dataReceivedEventHandler; }
453  inline void SetDataReceivedEventHandler(DataReceivedEventHandler&& dataReceivedEventHandler) { m_onDataReceived = std::move(dataReceivedEventHandler); }
457  inline void SetDataSentEventHandler(const DataSentEventHandler& dataSentEventHandler) { m_onDataSent = dataSentEventHandler; }
461  inline void SetDataSentEventHandler(DataSentEventHandler&& dataSentEventHandler) { m_onDataSent = std::move(dataSentEventHandler); }
465  inline void SetContinueRequestHandle(const ContinueRequestHandler& continueRequestHandler) { m_continueRequest = continueRequestHandler; }
469  inline void SetContinueRequestHandle(ContinueRequestHandler&& continueRequestHandler) { m_continueRequest = std::move(continueRequestHandler); }
470 
474  inline const DataReceivedEventHandler& GetDataReceivedEventHandler() const { return m_onDataReceived; }
478  inline const DataSentEventHandler& GetDataSentEventHandler() const { return m_onDataSent; }
479 
480  inline const ContinueRequestHandler& GetContinueRequestHandler() const { return m_continueRequest; }
481 
485  inline const Aws::String& GetSigningAccessKey() const { return m_signingAccessKey; }
489  inline void SetSigningAccessKey(const Aws::String& accessKey) { m_signingAccessKey = accessKey; }
490 
494  inline const Aws::String& GetSigningRegion() const { return m_signingRegion; }
498  inline void SetSigningRegion(const Aws::String& region) { m_signingRegion = region; }
499 
505  virtual void AddRequestMetric(const Aws::String& key, int64_t value) { m_httpRequestMetrics.emplace(key, value); }
506 
510  virtual void SetRequestMetrics(const Aws::Monitoring::HttpClientMetricsCollection& collection) { m_httpRequestMetrics = collection; }
511 
515  virtual const Aws::Monitoring::HttpClientMetricsCollection& GetRequestMetrics() const { return m_httpRequestMetrics; }
516 
523  Aws::String GetResolvedRemoteHost() const { return m_resolvedRemoteHost; }
524  void SetResolvedRemoteHost(const Aws::String& ip) { m_resolvedRemoteHost = ip; }
525 
526  bool IsEventStreamRequest() { return m_isEvenStreamRequest; }
527  void SetEventStreamRequest(bool eventStreamRequest) { m_isEvenStreamRequest = eventStreamRequest; }
528  private:
529  URI m_uri;
530  HttpMethod m_method;
531  bool m_isEvenStreamRequest;
532  DataReceivedEventHandler m_onDataReceived;
533  DataSentEventHandler m_onDataSent;
534  ContinueRequestHandler m_continueRequest;
535  Aws::String m_signingRegion;
536  Aws::String m_signingAccessKey;
537  Aws::String m_resolvedRemoteHost;
539  };
540 
541  } // namespace Http
542 } // namespace Aws
AWS_CORE_API const char HOST_HEADER[]
const Aws::String & GetAccept() const
Definition: HttpRequest.h:202
void SetCookie(const Aws::String &value)
Definition: HttpRequest.h:323
std::function< bool(const HttpRequest *)> ContinueRequestHandler
Definition: HttpRequest.h:60
AWS_CORE_API const char ACCEPT_HEADER[]
AWS_CORE_API const char AMZ_TARGET_HEADER[]
const Aws::String & GetQueryString() const
Definition: HttpRequest.h:150
HttpMethod GetMethod() const
Definition: HttpRequest.h:143
const Aws::String & GetDate() const
Definition: HttpRequest.h:183
bool HasDate() const
Definition: HttpRequest.h:176
const Aws::String & GetTransferEncoding() const
Definition: HttpRequest.h:373
void SetDataReceivedEventHandler(const DataReceivedEventHandler &dataReceivedEventHandler)
Definition: HttpRequest.h:449
virtual void AddRequestMetric(const Aws::String &key, int64_t value)
Definition: HttpRequest.h:505
const ContinueRequestHandler & GetContinueRequestHandler() const
Definition: HttpRequest.h:480
bool HasAcceptEncoding() const
Definition: HttpRequest.h:233
bool HasAuthorization() const
Definition: HttpRequest.h:252
const Aws::String & GetCookie() const
Definition: HttpRequest.h:316
void SetAcceptEncoding(const Aws::String &value)
Definition: HttpRequest.h:247
const Aws::String & GetAcceptEncoding() const
Definition: HttpRequest.h:240
void SetAwsAuthorization(const Aws::String &value)
Definition: HttpRequest.h:285
void SetResolvedRemoteHost(const Aws::String &ip)
Definition: HttpRequest.h:524
AWS_CORE_API const char ACCEPT_CHAR_SET_HEADER[]
const Aws::String & GetAcceptCharSet() const
Definition: HttpRequest.h:221
const Aws::String & GetVia() const
Definition: HttpRequest.h:411
void SetAwsSessionToken(const Aws::String &value)
Definition: HttpRequest.h:304
bool HasCookie() const
Definition: HttpRequest.h:309
Aws::Map< Aws::String, Aws::String > HeaderValueCollection
Definition: HttpTypes.h:53
AWS_CORE_API const char AWS_SECURITY_TOKEN[]
AWS_CORE_API const char CONTENT_TYPE_HEADER[]
void SetApiVersion(const Aws::String &value)
Definition: HttpRequest.h:441
void SetAcceptCharSet(const Aws::String &value)
Definition: HttpRequest.h:228
void SetVia(const Aws::String &value)
Definition: HttpRequest.h:418
const Aws::String & GetApiVersion() const
Definition: HttpRequest.h:434
const Aws::String & GetUserAgent() const
Definition: HttpRequest.h:392
void AddQueryStringParameter(const char *key, const Aws::String &value)
Definition: HttpRequest.h:171
bool HasTransferEncoding() const
Definition: HttpRequest.h:366
void SetTransferEncoding(const Aws::String &value)
Definition: HttpRequest.h:380
const DataReceivedEventHandler & GetDataReceivedEventHandler() const
Definition: HttpRequest.h:474
virtual void SetRequestMetrics(const Aws::Monitoring::HttpClientMetricsCollection &collection)
Definition: HttpRequest.h:510
void SetUserAgent(const Aws::String &value)
Definition: HttpRequest.h:399
bool HasAcceptCharSet() const
Definition: HttpRequest.h:214
AWS_CORE_API const char SDK_INVOCATION_ID_HEADER[]
std::function< void(const HttpRequest *, long long)> DataSentEventHandler
Definition: HttpRequest.h:56
const Aws::String & GetContentType() const
Definition: HttpRequest.h:354
Aws::String GetURIString(bool includeQueryString=true) const
Definition: HttpRequest.h:136
AWS_CORE_API const char CHUNKED_VALUE[]
const char *const name
Definition: cJSON.h:262
const DataSentEventHandler & GetDataSentEventHandler() const
Definition: HttpRequest.h:478
Aws::String GetResolvedRemoteHost() const
Definition: HttpRequest.h:523
void SetDataSentEventHandler(const DataSentEventHandler &dataSentEventHandler)
Definition: HttpRequest.h:457
void SetSigningAccessKey(const Aws::String &accessKey)
Definition: HttpRequest.h:489
void SetContinueRequestHandle(const ContinueRequestHandler &continueRequestHandler)
Definition: HttpRequest.h:465
AWS_CORE_API const char CONTENT_MD5_HEADER[]
AWS_CORE_API const char ACCEPT_ENCODING_HEADER[]
void SetContinueRequestHandle(ContinueRequestHandler &&continueRequestHandler)
Definition: HttpRequest.h:469
AWS_CORE_API const char TRANSFER_ENCODING_HEADER[]
const Aws::String & GetContentLength() const
Definition: HttpRequest.h:335
bool HasApiVersion() const
Definition: HttpRequest.h:426
Aws::MultiMap< Aws::String, Aws::String > QueryStringParameterCollection
Definition: URI.h:26
bool HasUserAgent() const
Definition: HttpRequest.h:385
void SetDate(const Aws::String &value)
Definition: HttpRequest.h:190
QueryStringParameterCollection GetQueryStringParameters() const
Definition: HttpRequest.h:164
AWS_CORE_API const char COOKIE_HEADER[]
void SetEventStreamRequest(bool eventStreamRequest)
Definition: HttpRequest.h:527
void SetSigningRegion(const Aws::String &region)
Definition: HttpRequest.h:498
const Aws::String & GetSigningAccessKey() const
Definition: HttpRequest.h:485
void SetAccept(const Aws::String &value)
Definition: HttpRequest.h:209
bool HasAwsAuthorization() const
Definition: HttpRequest.h:271
AWS_CORE_API const char DATE_HEADER[]
AWS_CORE_API const char AWS_DATE_HEADER[]
AWS_CORE_API const char VIA_HEADER[]
AWS_CORE_API const char AUTHORIZATION_HEADER[]
void SetAuthorization(const Aws::String &value)
Definition: HttpRequest.h:266
bool HasContentType() const
Definition: HttpRequest.h:347
const Aws::String & GetAwsAuthorization() const
Definition: HttpRequest.h:278
bool HasContentLength() const
Definition: HttpRequest.h:328
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97
void SetDataReceivedEventHandler(DataReceivedEventHandler &&dataReceivedEventHandler)
Definition: HttpRequest.h:453
const Aws::String & GetAwsSessionToken() const
Definition: HttpRequest.h:297
AWS_CORE_API const char CONTENT_LENGTH_HEADER[]
const URI & GetUri() const
Definition: HttpRequest.h:131
AWS_CORE_API const char SDK_REQUEST_HEADER[]
bool HasAwsSessionToken() const
Definition: HttpRequest.h:290
AWS_CORE_API const char USER_AGENT_HEADER[]
Aws::Map< Aws::String, int64_t > HttpClientMetricsCollection
void SetContentLength(const Aws::String &value)
Definition: HttpRequest.h:342
void SetDataSentEventHandler(DataSentEventHandler &&dataSentEventHandler)
Definition: HttpRequest.h:461
AWS_CORE_API const char AWS_AUTHORIZATION_HEADER[]
bool HasAccept() const
Definition: HttpRequest.h:195
const Aws::String & GetAuthorization() const
Definition: HttpRequest.h:259
HttpRequest(const URI &uri, HttpMethod method)
Definition: HttpRequest.h:71
virtual const Aws::Monitoring::HttpClientMetricsCollection & GetRequestMetrics() const
Definition: HttpRequest.h:515
void SetContentType(const Aws::String &value)
Definition: HttpRequest.h:361
#define AWS_CORE_API
Definition: Core_EXPORTS.h:25
AWS_CORE_API const char API_VERSION_HEADER[]
AWS_CORE_API const char X_AMZ_EXPIRES_HEADER[]
std::function< Aws::IOStream *(void) > IOStreamFactory
Definition: AWSStreamFwd.h:25
std::function< void(const HttpRequest *, HttpResponse *, long long)> DataReceivedEventHandler
Definition: HttpRequest.h:47
const Aws::String & GetSigningRegion() const
Definition: HttpRequest.h:494