AWS SDK for C++

AWS SDK for C++ Version 1.11.440

Loading...
Searching...
No Matches
HttpResponse.h
1
6#pragma once
7
8#include <aws/core/Core_EXPORTS.h>
9#include <aws/core/http/HttpRequest.h>
10#include <aws/core/http/HttpTypes.h>
11#include <aws/core/utils/memory/AWSMemory.h>
12#include <aws/core/utils/memory/stl/AWSStreamFwd.h>
13#include <aws/core/client/CoreErrors.h>
14
15namespace Aws
16{
17 namespace Utils
18 {
19 namespace Stream
20 {
21 class ResponseStream;
22 }
23 }
24 namespace Http
25 {
30 {
32 CONTINUE = 100,
34 PROCESSING = 102,
35 OK = 200,
36 CREATED = 201,
37 ACCEPTED = 202,
39 NO_CONTENT = 204,
40 RESET_CONTENT = 205,
41 PARTIAL_CONTENT = 206,
42 MULTI_STATUS = 207,
43 ALREADY_REPORTED = 208,
44 IM_USED = 226,
45 MULTIPLE_CHOICES = 300,
47 FOUND = 302,
48 SEE_OTHER = 303,
49 NOT_MODIFIED = 304,
50 USE_PROXY = 305,
51 SWITCH_PROXY = 306,
54 BAD_REQUEST = 400,
55 UNAUTHORIZED = 401,
56 PAYMENT_REQUIRED = 402,
57 FORBIDDEN = 403,
58 NOT_FOUND = 404,
60 NOT_ACCEPTABLE = 406,
62 REQUEST_TIMEOUT = 408,
63 CONFLICT = 409,
64 GONE = 410,
65 LENGTH_REQUIRED = 411,
72 IM_A_TEAPOT = 418,
74 METHOD_FAILURE = 420,
75 UNPROC_ENTITY = 422,
76 LOCKED = 423,
78 UPGRADE_REQUIRED = 426,
82 LOGIN_TIMEOUT = 440,
83 NO_RESPONSE = 444,
84 RETRY_WITH = 449,
85 BLOCKED = 450,
86 REDIRECT = 451,
88 CERT_ERROR = 495,
89 NO_CERT = 496,
90 HTTP_TO_HTTPS = 497,
93 NOT_IMPLEMENTED = 501,
94 BAD_GATEWAY = 502,
96 GATEWAY_TIMEOUT = 504,
100 LOOP_DETECTED = 508,
102 NOT_EXTENDED = 510,
106 };
107
112
114 {
115 switch (responseCode)
116 {
128 return true;
129 default:
130 return false;
131 }
132 }
133
137 class AWS_CORE_API HttpResponse
138 {
139 public:
143 HttpResponse(const std::shared_ptr<const HttpRequest>& originatingRequest) :
144 m_httpRequest(originatingRequest),
145 m_responseCode(HttpResponseCode::REQUEST_NOT_MADE),
146 m_hasClientError(false),
147 m_clientErrorType(Aws::Client::CoreErrors::OK)
148 {}
149
150 virtual ~HttpResponse() = default;
151
155 virtual inline const HttpRequest& GetOriginatingRequest() const { return *m_httpRequest; }
156
160 virtual inline void SetOriginatingRequest(const std::shared_ptr<const HttpRequest>& httpRequest) { m_httpRequest = httpRequest; }
161
169 virtual bool HasHeader(const char* headerName) const = 0;
173 virtual const Aws::String& GetHeader(const Aws::String& headerName) const = 0;
177 virtual inline HttpResponseCode GetResponseCode() const { return m_responseCode; }
181 virtual inline void SetResponseCode(HttpResponseCode httpResponseCode) { m_responseCode = httpResponseCode; }
185 virtual const Aws::String& GetContentType() const { return GetHeader(Http::CONTENT_TYPE_HEADER); }
189 virtual Aws::IOStream& GetResponseBody() const = 0;
198 virtual void AddHeader(const Aws::String&, const Aws::String&) = 0;
206 virtual void AddHeader(const Aws::String& headerName, Aws::String&& headerValue) { AddHeader(headerName, headerValue); };
210 virtual void SetContentType(const Aws::String& contentType) { AddHeader("content-type", contentType); }
211
212 inline bool HasClientError() const { return m_hasClientError; }
213 inline void SetClientErrorType(Aws::Client::CoreErrors errorType) {m_hasClientError = true; m_clientErrorType = errorType;}
214 inline Aws::Client::CoreErrors GetClientErrorType() { return m_clientErrorType; }
215
216 inline const Aws::String &GetClientErrorMessage() const { return m_clientErrorMessage; }
217 inline void SetClientErrorMessage(const Aws::String &error) { m_clientErrorMessage = error; }
218
219 private:
221 HttpResponse& operator = (const HttpResponse&);
222
223 std::shared_ptr<const HttpRequest> m_httpRequest;
224 HttpResponseCode m_responseCode;
225 // Error generated by http client, SDK or users, indicating non service error during http request
226 bool m_hasClientError;
227 Aws::Client::CoreErrors m_clientErrorType;
228 Aws::String m_clientErrorMessage;
229 };
230
231 } // namespace Http
232} // namespace Aws
233
234
HttpResponse(const std::shared_ptr< const HttpRequest > &originatingRequest)
virtual ~HttpResponse()=default
virtual void SetContentType(const Aws::String &contentType)
virtual bool HasHeader(const char *headerName) const =0
virtual void SetResponseCode(HttpResponseCode httpResponseCode)
void SetClientErrorType(Aws::Client::CoreErrors errorType)
virtual HeaderValueCollection GetHeaders() const =0
virtual void AddHeader(const Aws::String &headerName, Aws::String &&headerValue)
virtual HttpResponseCode GetResponseCode() const
virtual Aws::IOStream & GetResponseBody() const =0
Aws::Client::CoreErrors GetClientErrorType()
const Aws::String & GetClientErrorMessage() const
virtual const Aws::String & GetHeader(const Aws::String &headerName) const =0
virtual const Aws::String & GetContentType() const
virtual Utils::Stream::ResponseStream && SwapResponseStreamOwnership()=0
bool HasClientError() const
virtual void SetOriginatingRequest(const std::shared_ptr< const HttpRequest > &httpRequest)
virtual const HttpRequest & GetOriginatingRequest() const
void SetClientErrorMessage(const Aws::String &error)
virtual void AddHeader(const Aws::String &, const Aws::String &)=0
bool IsRetryableHttpResponseCode(HttpResponseCode responseCode)
Aws::Map< Aws::String, Aws::String > HeaderValueCollection
Definition HttpTypes.h:62
AWS_CORE_API Aws::OStream & operator<<(Aws::OStream &oStream, HttpResponseCode code)
std::basic_iostream< char, std::char_traits< char > > IOStream
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition AWSString.h:97
std::basic_ostream< char, std::char_traits< char > > OStream