AWS SDK for C++

AWS SDK for C++ Version 1.11.440

Loading...
Searching...
No Matches
HttpRequest.h
1
6#pragma once
7
8#include <aws/core/Core_EXPORTS.h>
9
10#include <aws/core/http/URI.h>
11#include <aws/core/http/HttpTypes.h>
12#include <aws/core/utils/memory/AWSMemory.h>
13#include <aws/core/utils/memory/stl/AWSStreamFwd.h>
14#include <aws/core/utils/stream/ResponseStream.h>
15#include <aws/core/utils/UUID.h>
16#include <aws/core/monitoring/HttpClientMetrics.h>
17#include <memory>
18#include <functional>
19
20namespace Aws
21{
22 namespace Crt
23 {
24 namespace Http
25 {
26 class HttpRequest;
27 }
28 }
29 namespace Utils
30 {
31 namespace Crypto
32 {
33 class Hash;
34 }
35 }
36 namespace Http
37 {
38 extern AWS_CORE_API const char DATE_HEADER[];
39 extern AWS_CORE_API const char AWS_DATE_HEADER[];
40 extern AWS_CORE_API const char AWS_SECURITY_TOKEN[];
41 extern AWS_CORE_API const char ACCEPT_HEADER[];
42 extern AWS_CORE_API const char ACCEPT_CHAR_SET_HEADER[];
43 extern AWS_CORE_API const char ACCEPT_ENCODING_HEADER[];
44 extern AWS_CORE_API const char AUTHORIZATION_HEADER[];
45 extern AWS_CORE_API const char AWS_AUTHORIZATION_HEADER[];
46 extern AWS_CORE_API const char COOKIE_HEADER[];
47 extern AWS_CORE_API const char DECODED_CONTENT_LENGTH_HEADER[];
48 extern AWS_CORE_API const char CONTENT_LENGTH_HEADER[];
49 extern AWS_CORE_API const char CONTENT_TYPE_HEADER[];
50 extern AWS_CORE_API const char CONTENT_ENCODING_HEADER[];
51 extern AWS_CORE_API const char TRANSFER_ENCODING_HEADER[];
52 extern AWS_CORE_API const char USER_AGENT_HEADER[];
53 extern AWS_CORE_API const char VIA_HEADER[];
54 extern AWS_CORE_API const char HOST_HEADER[];
55 extern AWS_CORE_API const char AMZ_TARGET_HEADER[];
56 extern AWS_CORE_API const char X_AMZ_EXPIRES_HEADER[];
57 extern AWS_CORE_API const char CONTENT_MD5_HEADER[];
58 extern AWS_CORE_API const char API_VERSION_HEADER[];
59 extern AWS_CORE_API const char AWS_TRAILER_HEADER[];
60 extern AWS_CORE_API const char SDK_INVOCATION_ID_HEADER[];
61 extern AWS_CORE_API const char SDK_REQUEST_HEADER[];
62 extern AWS_CORE_API const char X_AMZN_TRACE_ID_HEADER[];
63 extern AWS_CORE_API const char CHUNKED_VALUE[];
64 extern AWS_CORE_API const char AWS_CHUNKED_VALUE[];
65 extern AWS_CORE_API const char X_AMZN_ERROR_TYPE[];
66
67 class HttpRequest;
68 class HttpResponse;
69
73 typedef std::function<void(const HttpRequest*, HttpResponse*)> HeadersReceivedEventHandler;
77 typedef std::function<void(const HttpRequest*, HttpResponse*, long long)> DataReceivedEventHandler;
81 typedef std::function<void(const HttpRequest*, long long)> DataSentEventHandler;
85 typedef std::function<bool(const HttpRequest*)> ContinueRequestHandler;
86
93 };
94
98 class AWS_CORE_API HttpRequest
99 {
100 public:
104 HttpRequest(const URI& uri, HttpMethod method) :
105 m_uri(uri), m_method(method), m_isEvenStreamRequest(false)
106 {}
107
108 virtual ~HttpRequest() {}
109
117 virtual const Aws::String& GetHeaderValue(const char* headerName) const = 0;
119
122 virtual void SetHeaderValue(const char* headerName, const Aws::String& headerValue) = 0;
123 virtual void SetHeaderValue(const Aws::String& headerName, const Aws::String& headerValue) = 0;
125
129 virtual void DeleteHeader(const char* headerName) = 0;
133 virtual void AddContentBody(const std::shared_ptr<Aws::IOStream>& strContent) = 0;
137 virtual const std::shared_ptr<Aws::IOStream>& GetContentBody() const = 0;
141 virtual bool HasHeader(const char* name) const = 0;
145 virtual int64_t GetSize() const = 0;
153 virtual void SetResponseStreamFactory(const Aws::IOStreamFactory& factory) = 0;
157 inline URI& GetUri()
158 {
159 return m_uri;
160 }
164 const URI& GetUri() const { return m_uri; }
169 inline Aws::String GetURIString(bool includeQueryString = true) const
170 {
171 return m_uri.GetURIString(includeQueryString);
172 }
176 inline HttpMethod GetMethod() const
177 {
178 return m_method;
179 }
183 inline const Aws::String& GetQueryString() const
184 {
185 return m_uri.GetQueryString();
186 }
191 {
192 m_uri.CanonicalizeQueryString();
193 }
198 {
199 return m_uri.GetQueryStringParameters();
200 }
204 inline void AddQueryStringParameter(const char* key, const Aws::String& value)
205 {
206 m_uri.AddQueryStringParameter(key, value);
207 }
208
209 inline bool HasDate() const
210 {
211 return HasHeader(DATE_HEADER);
212 }
216 inline const Aws::String& GetDate() const
217 {
218 return GetHeaderValue(DATE_HEADER);
219 }
223 inline void SetDate(const Aws::String& value)
224 {
225 SetHeaderValue(DATE_HEADER, value);
226 }
227
228 inline bool HasAccept() const
229 {
230 return HasHeader(ACCEPT_HEADER);
231 }
235 inline const Aws::String& GetAccept() const
236 {
237 return GetHeaderValue(ACCEPT_HEADER);
238 }
242 inline void SetAccept(const Aws::String& value)
243 {
244 SetHeaderValue(ACCEPT_HEADER, value);
245 }
246
247 inline bool HasAcceptCharSet() const
248 {
249 return HasHeader(ACCEPT_CHAR_SET_HEADER);
250 }
254 inline const Aws::String& GetAcceptCharSet() const
255 {
256 return GetHeaderValue(ACCEPT_CHAR_SET_HEADER);
257 }
261 inline void SetAcceptCharSet(const Aws::String& value)
262 {
263 SetHeaderValue(ACCEPT_CHAR_SET_HEADER, value);
264 }
265
266 inline bool HasAcceptEncoding() const
267 {
268 return HasHeader(ACCEPT_ENCODING_HEADER);
269 }
273 inline const Aws::String& GetAcceptEncoding() const
274 {
275 return GetHeaderValue(ACCEPT_ENCODING_HEADER);
276 }
280 inline void SetAcceptEncoding(const Aws::String& value)
281 {
282 SetHeaderValue(ACCEPT_ENCODING_HEADER, value);
283 }
284
285 inline bool HasAuthorization() const
286 {
287 return HasHeader(AUTHORIZATION_HEADER);
288 }
292 inline const Aws::String& GetAuthorization() const
293 {
294 return GetHeaderValue(AUTHORIZATION_HEADER);
295 }
299 inline void SetAuthorization(const Aws::String& value)
300 {
301 SetHeaderValue(AUTHORIZATION_HEADER, value);
302 }
303
304 inline bool HasAwsAuthorization() const
305 {
306 return HasHeader(AWS_AUTHORIZATION_HEADER);
307 }
311 inline const Aws::String& GetAwsAuthorization() const
312 {
313 return GetHeaderValue(AWS_AUTHORIZATION_HEADER);
314 }
318 inline void SetAwsAuthorization(const Aws::String& value)
319 {
320 SetHeaderValue(AWS_AUTHORIZATION_HEADER, value);
321 }
322
323 inline bool HasAwsSessionToken() const
324 {
325 return HasHeader(AWS_SECURITY_TOKEN);
326 }
330 inline const Aws::String& GetAwsSessionToken() const
331 {
332 return GetHeaderValue(AWS_SECURITY_TOKEN);
333 }
337 inline void SetAwsSessionToken(const Aws::String& value)
338 {
339 SetHeaderValue(AWS_SECURITY_TOKEN, value);
340 }
341
342 inline bool HasCookie() const
343 {
344 return HasHeader(COOKIE_HEADER);
345 }
349 inline const Aws::String& GetCookie() const
350 {
351 return GetHeaderValue(COOKIE_HEADER);
352 }
356 inline void SetCookie(const Aws::String& value)
357 {
358 SetHeaderValue(COOKIE_HEADER, value);
359 }
360
361 inline bool HasContentLength() const
362 {
363 return HasHeader(CONTENT_LENGTH_HEADER);
364 }
368 inline const Aws::String& GetContentLength() const
369 {
370 return GetHeaderValue(CONTENT_LENGTH_HEADER);
371 }
375 inline void SetContentLength(const Aws::String& value)
376 {
377 SetHeaderValue(CONTENT_LENGTH_HEADER, value);
378 }
379
380 inline bool HasContentType() const
381 {
382 return HasHeader(CONTENT_TYPE_HEADER);
383 }
387 inline const Aws::String& GetContentType() const
388 {
389 return GetHeaderValue(CONTENT_TYPE_HEADER);
390 }
394 inline void SetContentType(const Aws::String& value)
395 {
396 SetHeaderValue(CONTENT_TYPE_HEADER, value);
397 }
398
399 inline bool HasTransferEncoding() const
400 {
401 return HasHeader(TRANSFER_ENCODING_HEADER);
402 }
406 inline const Aws::String& GetTransferEncoding() const
407 {
408 return GetHeaderValue(TRANSFER_ENCODING_HEADER);
409 }
413 inline void SetTransferEncoding(const Aws::String& value)
414 {
415 SetHeaderValue(TRANSFER_ENCODING_HEADER, value);
416 }
417
418 inline bool HasUserAgent() const
419 {
420 return HasHeader(USER_AGENT_HEADER);
421 }
425 inline const Aws::String& GetUserAgent() const
426 {
427 return GetHeaderValue(USER_AGENT_HEADER);
428 }
432 inline void SetUserAgent(const Aws::String& value)
433 {
434 SetHeaderValue(USER_AGENT_HEADER, value);
435 }
436
437 inline bool HasVia() const
438 {
439 return HasHeader(VIA_HEADER);
440 }
444 inline const Aws::String& GetVia() const
445 {
446 return GetHeaderValue(VIA_HEADER);
447 }
451 inline void SetVia(const Aws::String& value)
452 {
453 SetHeaderValue(VIA_HEADER, value);
454 }
455
459 inline bool HasApiVersion() const
460 {
461 return HasHeader(API_VERSION_HEADER);
462 }
463
467 inline const Aws::String& GetApiVersion() const
468 {
469 return GetHeaderValue(API_VERSION_HEADER);
470 }
474 inline void SetApiVersion(const Aws::String& value)
475 {
476 SetHeaderValue(API_VERSION_HEADER, value);
477 }
478
480
483 inline void SetHeadersReceivedEventHandler(const HeadersReceivedEventHandler& headersReceivedEventHandler) { m_onHeadersReceived = headersReceivedEventHandler; }
484 inline void SetHeadersReceivedEventHandler(HeadersReceivedEventHandler&& headersReceivedEventHandler) { m_onHeadersReceived = std::move(headersReceivedEventHandler); }
486
488
491 inline void SetDataReceivedEventHandler(const DataReceivedEventHandler& dataReceivedEventHandler) { m_onDataReceived = dataReceivedEventHandler; }
492 inline void SetDataReceivedEventHandler(DataReceivedEventHandler&& dataReceivedEventHandler) { m_onDataReceived = std::move(dataReceivedEventHandler); }
494
496
499 inline void SetDataSentEventHandler(const DataSentEventHandler& dataSentEventHandler) { m_onDataSent = dataSentEventHandler; }
500 inline void SetDataSentEventHandler(DataSentEventHandler&& dataSentEventHandler) { m_onDataSent = std::move(dataSentEventHandler); }
502
504
507 inline void SetContinueRequestHandle(const ContinueRequestHandler& continueRequestHandler) { m_continueRequest = continueRequestHandler; }
508 inline void SetContinueRequestHandle(ContinueRequestHandler&& continueRequestHandler) { m_continueRequest = std::move(continueRequestHandler); }
510
514 inline const HeadersReceivedEventHandler & GetHeadersReceivedEventHandler() const { return m_onHeadersReceived; }
518 inline const DataReceivedEventHandler& GetDataReceivedEventHandler() const { return m_onDataReceived; }
522 inline const DataSentEventHandler& GetDataSentEventHandler() const { return m_onDataSent; }
523
524 inline const ContinueRequestHandler& GetContinueRequestHandler() const { return m_continueRequest; }
525
529 inline const Aws::String& GetSigningAccessKey() const { return m_signingAccessKey; }
533 inline void SetSigningAccessKey(const Aws::String& accessKey) { m_signingAccessKey = accessKey; }
534
538 inline const Aws::String& GetSigningRegion() const { return m_signingRegion; }
542 inline void SetSigningRegion(const Aws::String& region) { m_signingRegion = region; }
543
549 virtual void AddRequestMetric(const Aws::String& key, int64_t value) { m_httpRequestMetrics.emplace(key, value); }
550
554 virtual void SetRequestMetrics(const Aws::Monitoring::HttpClientMetricsCollection& collection) { m_httpRequestMetrics = collection; }
555
559 virtual const Aws::Monitoring::HttpClientMetricsCollection& GetRequestMetrics() const { return m_httpRequestMetrics; }
560
567 Aws::String GetResolvedRemoteHost() const { return m_resolvedRemoteHost; }
568 void SetResolvedRemoteHost(const Aws::String& ip) { m_resolvedRemoteHost = ip; }
569
570 bool IsEventStreamRequest() { return m_isEvenStreamRequest; }
571 void SetEventStreamRequest(bool eventStreamRequest) { m_isEvenStreamRequest = eventStreamRequest; }
572
573 virtual std::shared_ptr<Aws::Crt::Http::HttpRequest> ToCrtHttpRequest();
574
575 void SetRequestHash(const Aws::String& algorithmName, const std::shared_ptr<Aws::Utils::Crypto::Hash>& hash)
576 {
577 m_requestHash = std::make_pair(algorithmName, hash);
578 }
579 const std::pair<Aws::String, std::shared_ptr<Aws::Utils::Crypto::Hash>>& GetRequestHash() const { return m_requestHash; }
580
581 void AddResponseValidationHash(const Aws::String& algorithmName, const std::shared_ptr<Aws::Utils::Crypto::Hash>& hash)
582 {
583 m_responseValidationHashes.emplace_back(algorithmName, hash);
584 }
586
587 inline void SetServiceSpecificParameters(const std::shared_ptr<ServiceSpecificParameters> &serviceSpecificParameters) { m_serviceSpecificParameters = serviceSpecificParameters; }
588
589 inline std::shared_ptr<ServiceSpecificParameters> GetServiceSpecificParameters() { return m_serviceSpecificParameters; }
590
591 private:
592 URI m_uri;
593 HttpMethod m_method;
594 bool m_isEvenStreamRequest = false;
595 HeadersReceivedEventHandler m_onHeadersReceived;
596 DataReceivedEventHandler m_onDataReceived;
597 DataSentEventHandler m_onDataSent;
598 ContinueRequestHandler m_continueRequest;
599 Aws::String m_signingRegion;
600 Aws::String m_signingAccessKey;
601 Aws::String m_resolvedRemoteHost;
603 std::pair<Aws::String, std::shared_ptr<Aws::Utils::Crypto::Hash>> m_requestHash;
605 std::shared_ptr<ServiceSpecificParameters> m_serviceSpecificParameters;
606 };
607
608 } // namespace Http
609} // namespace Aws
std::shared_ptr< ServiceSpecificParameters > GetServiceSpecificParameters()
const Aws::String & GetQueryString() const
bool HasAwsSessionToken() const
bool HasContentLength() const
const ContinueRequestHandler & GetContinueRequestHandler() const
HttpMethod GetMethod() const
QueryStringParameterCollection GetQueryStringParameters() const
bool HasAwsAuthorization() const
virtual void SetHeaderValue(const Aws::String &headerName, const Aws::String &headerValue)=0
void SetApiVersion(const Aws::String &value)
virtual void SetResponseStreamFactory(const Aws::IOStreamFactory &factory)=0
Aws::String GetResolvedRemoteHost() const
bool HasContentType() const
bool HasApiVersion() const
virtual HeaderValueCollection GetHeaders() const =0
const Aws::String & GetCookie() const
const URI & GetUri() const
const Aws::String & GetApiVersion() const
void SetRequestHash(const Aws::String &algorithmName, const std::shared_ptr< Aws::Utils::Crypto::Hash > &hash)
virtual void AddContentBody(const std::shared_ptr< Aws::IOStream > &strContent)=0
void SetSigningRegion(const Aws::String &region)
void SetContinueRequestHandle(const ContinueRequestHandler &continueRequestHandler)
void SetCookie(const Aws::String &value)
virtual const Aws::IOStreamFactory & GetResponseStreamFactory() const =0
const Aws::String & GetAwsSessionToken() const
const DataSentEventHandler & GetDataSentEventHandler() const
const DataReceivedEventHandler & GetDataReceivedEventHandler() const
virtual void DeleteHeader(const char *headerName)=0
const Aws::String & GetAwsAuthorization() const
void SetAwsSessionToken(const Aws::String &value)
bool HasAcceptCharSet() const
virtual const Aws::String & GetHeaderValue(const char *headerName) const =0
virtual std::shared_ptr< Aws::Crt::Http::HttpRequest > ToCrtHttpRequest()
const Aws::String & GetTransferEncoding() const
const Aws::String & GetDate() const
HttpRequest(const URI &uri, HttpMethod method)
void SetUserAgent(const Aws::String &value)
void SetHeadersReceivedEventHandler(const HeadersReceivedEventHandler &headersReceivedEventHandler)
void SetDataReceivedEventHandler(DataReceivedEventHandler &&dataReceivedEventHandler)
void SetAuthorization(const Aws::String &value)
void SetVia(const Aws::String &value)
void SetDataReceivedEventHandler(const DataReceivedEventHandler &dataReceivedEventHandler)
Aws::String GetURIString(bool includeQueryString=true) const
const Aws::String & GetAuthorization() const
void SetContentType(const Aws::String &value)
const HeadersReceivedEventHandler & GetHeadersReceivedEventHandler() const
const Aws::String & GetContentLength() const
void SetAcceptEncoding(const Aws::String &value)
const Aws::Vector< std::pair< Aws::String, std::shared_ptr< Aws::Utils::Crypto::Hash > > > & GetResponseValidationHashes() const
const Aws::String & GetSigningAccessKey() const
const Aws::String & GetSigningRegion() const
const Aws::String & GetAccept() const
void SetDataSentEventHandler(DataSentEventHandler &&dataSentEventHandler)
void AddQueryStringParameter(const char *key, const Aws::String &value)
virtual const Aws::Monitoring::HttpClientMetricsCollection & GetRequestMetrics() const
void SetSigningAccessKey(const Aws::String &accessKey)
void SetResolvedRemoteHost(const Aws::String &ip)
void SetHeadersReceivedEventHandler(HeadersReceivedEventHandler &&headersReceivedEventHandler)
virtual void SetRequestMetrics(const Aws::Monitoring::HttpClientMetricsCollection &collection)
void SetDataSentEventHandler(const DataSentEventHandler &dataSentEventHandler)
const Aws::String & GetAcceptCharSet() const
bool HasUserAgent() const
const Aws::String & GetAcceptEncoding() const
const Aws::String & GetContentType() const
void SetContentLength(const Aws::String &value)
bool HasAuthorization() const
virtual const std::shared_ptr< Aws::IOStream > & GetContentBody() const =0
void SetEventStreamRequest(bool eventStreamRequest)
virtual void AddRequestMetric(const Aws::String &key, int64_t value)
void SetContinueRequestHandle(ContinueRequestHandler &&continueRequestHandler)
void AddResponseValidationHash(const Aws::String &algorithmName, const std::shared_ptr< Aws::Utils::Crypto::Hash > &hash)
bool HasAcceptEncoding() const
void SetAwsAuthorization(const Aws::String &value)
virtual bool HasHeader(const char *name) const =0
bool HasTransferEncoding() const
const Aws::String & GetVia() const
virtual int64_t GetSize() const =0
void SetServiceSpecificParameters(const std::shared_ptr< ServiceSpecificParameters > &serviceSpecificParameters)
const std::pair< Aws::String, std::shared_ptr< Aws::Utils::Crypto::Hash > > & GetRequestHash() const
const Aws::String & GetUserAgent() const
void SetAccept(const Aws::String &value)
void SetTransferEncoding(const Aws::String &value)
virtual void SetHeaderValue(const char *headerName, const Aws::String &headerValue)=0
void SetDate(const Aws::String &value)
void SetAcceptCharSet(const Aws::String &value)
std::function< void(const HttpRequest *, HttpResponse *)> HeadersReceivedEventHandler
Definition HttpRequest.h:73
AWS_CORE_API const char ACCEPT_CHAR_SET_HEADER[]
AWS_CORE_API const char USER_AGENT_HEADER[]
AWS_CORE_API const char SDK_REQUEST_HEADER[]
std::function< void(const HttpRequest *, HttpResponse *, long long)> DataReceivedEventHandler
Definition HttpRequest.h:77
AWS_CORE_API const char AWS_AUTHORIZATION_HEADER[]
AWS_CORE_API const char CHUNKED_VALUE[]
AWS_CORE_API const char ACCEPT_ENCODING_HEADER[]
Aws::MultiMap< Aws::String, Aws::String > QueryStringParameterCollection
Definition URI.h:32
std::function< void(const HttpRequest *, long long)> DataSentEventHandler
Definition HttpRequest.h:81
AWS_CORE_API const char DECODED_CONTENT_LENGTH_HEADER[]
AWS_CORE_API const char CONTENT_LENGTH_HEADER[]
AWS_CORE_API const char X_AMZN_TRACE_ID_HEADER[]
AWS_CORE_API const char AUTHORIZATION_HEADER[]
AWS_CORE_API const char CONTENT_ENCODING_HEADER[]
AWS_CORE_API const char DATE_HEADER[]
AWS_CORE_API const char AWS_SECURITY_TOKEN[]
AWS_CORE_API const char API_VERSION_HEADER[]
AWS_CORE_API const char AWS_CHUNKED_VALUE[]
AWS_CORE_API const char CONTENT_MD5_HEADER[]
AWS_CORE_API const char X_AMZN_ERROR_TYPE[]
std::function< bool(const HttpRequest *)> ContinueRequestHandler
Definition HttpRequest.h:85
AWS_CORE_API const char VIA_HEADER[]
AWS_CORE_API const char ACCEPT_HEADER[]
AWS_CORE_API const char AWS_DATE_HEADER[]
AWS_CORE_API const char AMZ_TARGET_HEADER[]
AWS_CORE_API const char AWS_TRAILER_HEADER[]
AWS_CORE_API const char CONTENT_TYPE_HEADER[]
AWS_CORE_API const char TRANSFER_ENCODING_HEADER[]
AWS_CORE_API const char HOST_HEADER[]
Aws::Map< Aws::String, Aws::String > HeaderValueCollection
Definition HttpTypes.h:62
AWS_CORE_API const char X_AMZ_EXPIRES_HEADER[]
AWS_CORE_API const char COOKIE_HEADER[]
AWS_CORE_API const char SDK_INVOCATION_ID_HEADER[]
Aws::Map< Aws::String, int64_t > HttpClientMetricsCollection
std::map< K, V, std::less< K >, Aws::Allocator< std::pair< const K, V > > > Map
Definition AWSMap.h:20
std::function< Aws::IOStream *(void) > IOStreamFactory
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition AWSString.h:97
std::vector< T, Aws::Allocator< T > > Vector
Definition AWSVector.h:17
Aws::Map< Aws::String, Aws::String > parameterMap
Definition HttpRequest.h:92