AWS SDK for C++
AWS SDK for C++
Loading...
Searching...
No Matches
HttpResponse.h
Go to the documentation of this file.
1
6#pragma once
7
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 {
127 return true;
128 default:
129 return false;
130 }
131 }
132
137 {
138 public:
142 HttpResponse(const std::shared_ptr<const HttpRequest>& originatingRequest) :
143 m_httpRequest(originatingRequest),
144 m_responseCode(HttpResponseCode::REQUEST_NOT_MADE),
145 m_hasClientError(false),
146 m_clientErrorType(Aws::Client::CoreErrors::OK)
147 {}
148
149 virtual ~HttpResponse() = default;
150
154 virtual inline const HttpRequest& GetOriginatingRequest() const { return *m_httpRequest; }
155
159 virtual inline void SetOriginatingRequest(const std::shared_ptr<const HttpRequest>& httpRequest) { m_httpRequest = httpRequest; }
160
168 virtual bool HasHeader(const char* headerName) const = 0;
172 virtual const Aws::String& GetHeader(const Aws::String& headerName) const = 0;
176 virtual inline HttpResponseCode GetResponseCode() const { return m_responseCode; }
180 virtual inline void SetResponseCode(HttpResponseCode httpResponseCode) { m_responseCode = httpResponseCode; }
184 virtual const Aws::String& GetContentType() const { return GetHeader(Http::CONTENT_TYPE_HEADER); }
188 virtual Aws::IOStream& GetResponseBody() const = 0;
197 virtual void AddHeader(const Aws::String&, const Aws::String&) = 0;
201 virtual void SetContentType(const Aws::String& contentType) { AddHeader("content-type", contentType); }
202
203 inline bool HasClientError() const { return m_hasClientError; }
204 inline void SetClientErrorType(Aws::Client::CoreErrors errorType) {m_hasClientError = true; m_clientErrorType = errorType;}
205 inline Aws::Client::CoreErrors GetClientErrorType() { return m_clientErrorType; }
206
207 inline const Aws::String &GetClientErrorMessage() const { return m_clientErrorMessage; }
208 inline void SetClientErrorMessage(const Aws::String &error) { m_clientErrorMessage = error; }
209
210 private:
212 HttpResponse& operator = (const HttpResponse&);
213
214 std::shared_ptr<const HttpRequest> m_httpRequest;
215 HttpResponseCode m_responseCode;
216 // Error generated by http client, SDK or users, indicating non service error during http request
217 bool m_hasClientError;
218 Aws::Client::CoreErrors m_clientErrorType;
219 Aws::String m_clientErrorMessage;
220 };
221
222 } // namespace Http
223} // namespace Aws
224
225
#define AWS_CORE_API
Definition: Core_EXPORTS.h:26
HttpResponse(const std::shared_ptr< const HttpRequest > &originatingRequest)
Definition: HttpResponse.h:142
virtual ~HttpResponse()=default
virtual void SetContentType(const Aws::String &contentType)
Definition: HttpResponse.h:201
virtual bool HasHeader(const char *headerName) const =0
virtual void SetResponseCode(HttpResponseCode httpResponseCode)
Definition: HttpResponse.h:180
void SetClientErrorType(Aws::Client::CoreErrors errorType)
Definition: HttpResponse.h:204
virtual HeaderValueCollection GetHeaders() const =0
virtual HttpResponseCode GetResponseCode() const
Definition: HttpResponse.h:176
virtual Aws::IOStream & GetResponseBody() const =0
Aws::Client::CoreErrors GetClientErrorType()
Definition: HttpResponse.h:205
const Aws::String & GetClientErrorMessage() const
Definition: HttpResponse.h:207
virtual const Aws::String & GetHeader(const Aws::String &headerName) const =0
virtual const Aws::String & GetContentType() const
Definition: HttpResponse.h:184
virtual Utils::Stream::ResponseStream && SwapResponseStreamOwnership()=0
bool HasClientError() const
Definition: HttpResponse.h:203
virtual void SetOriginatingRequest(const std::shared_ptr< const HttpRequest > &httpRequest)
Definition: HttpResponse.h:159
virtual const HttpRequest & GetOriginatingRequest() const
Definition: HttpResponse.h:154
void SetClientErrorMessage(const Aws::String &error)
Definition: HttpResponse.h:208
virtual void AddHeader(const Aws::String &, const Aws::String &)=0
bool IsRetryableHttpResponseCode(HttpResponseCode responseCode)
Definition: HttpResponse.h:113
Aws::Map< Aws::String, Aws::String > HeaderValueCollection
Definition: HttpTypes.h:53
AWS_CORE_API Aws::OStream & operator<<(Aws::OStream &oStream, HttpResponseCode code)
std::basic_iostream< char, std::char_traits< char > > IOStream
Definition: AWSStreamFwd.h:22
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
Definition: AWSStreamFwd.h:21