AWS SDK for C++  1.8.152
AWS SDK for C++
HttpResponse.h
Go to the documentation of this file.
1 
6 #pragma once
7 
14 
15 namespace Aws
16 {
17  namespace Utils
18  {
19  namespace Stream
20  {
21  class ResponseStream;
22  }
23  }
24  namespace Http
25  {
29  enum class HttpResponseCode
30  {
31  REQUEST_NOT_MADE = -1,
32  CONTINUE = 100,
33  SWITCHING_PROTOCOLS = 101,
34  PROCESSING = 102,
35  OK = 200,
36  CREATED = 201,
37  ACCEPTED = 202,
38  NON_AUTHORITATIVE_INFORMATION = 203,
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,
46  MOVED_PERMANENTLY = 301,
47  FOUND = 302,
48  SEE_OTHER = 303,
49  NOT_MODIFIED = 304,
50  USE_PROXY = 305,
51  SWITCH_PROXY = 306,
52  TEMPORARY_REDIRECT = 307,
53  PERMANENT_REDIRECT = 308,
54  BAD_REQUEST = 400,
55  UNAUTHORIZED = 401,
56  PAYMENT_REQUIRED = 402,
57  FORBIDDEN = 403,
58  NOT_FOUND = 404,
59  METHOD_NOT_ALLOWED = 405,
60  NOT_ACCEPTABLE = 406,
61  PROXY_AUTHENTICATION_REQUIRED = 407,
62  REQUEST_TIMEOUT = 408,
63  CONFLICT = 409,
64  GONE = 410,
65  LENGTH_REQUIRED = 411,
66  PRECONDITION_FAILED = 412,
67  REQUEST_ENTITY_TOO_LARGE = 413,
68  REQUEST_URI_TOO_LONG = 414,
69  UNSUPPORTED_MEDIA_TYPE = 415,
70  REQUESTED_RANGE_NOT_SATISFIABLE = 416,
71  EXPECTATION_FAILED = 417,
72  IM_A_TEAPOT = 418,
73  AUTHENTICATION_TIMEOUT = 419,
74  METHOD_FAILURE = 420,
75  UNPROC_ENTITY = 422,
76  LOCKED = 423,
77  FAILED_DEPENDENCY = 424,
78  UPGRADE_REQUIRED = 426,
79  PRECONDITION_REQUIRED = 427,
80  TOO_MANY_REQUESTS = 429,
81  REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
82  LOGIN_TIMEOUT = 440,
83  NO_RESPONSE = 444,
84  RETRY_WITH = 449,
85  BLOCKED = 450,
86  REDIRECT = 451,
87  REQUEST_HEADER_TOO_LARGE = 494,
88  CERT_ERROR = 495,
89  NO_CERT = 496,
90  HTTP_TO_HTTPS = 497,
91  CLIENT_CLOSED_TO_REQUEST = 499,
92  INTERNAL_SERVER_ERROR = 500,
93  NOT_IMPLEMENTED = 501,
94  BAD_GATEWAY = 502,
95  SERVICE_UNAVAILABLE = 503,
96  GATEWAY_TIMEOUT = 504,
97  HTTP_VERSION_NOT_SUPPORTED = 505,
98  VARIANT_ALSO_NEGOTIATES = 506,
99  INSUFFICIENT_STORAGE = 507,
100  LOOP_DETECTED = 508,
101  BANDWIDTH_LIMIT_EXCEEDED = 509,
102  NOT_EXTENDED = 510,
103  NETWORK_AUTHENTICATION_REQUIRED = 511,
104  NETWORK_READ_TIMEOUT = 598,
106  };
107 
109  {
110  switch (responseCode)
111  {
112  case HttpResponseCode::INTERNAL_SERVER_ERROR:
113  case HttpResponseCode::SERVICE_UNAVAILABLE:
114  case HttpResponseCode::TOO_MANY_REQUESTS:
115  case HttpResponseCode::BANDWIDTH_LIMIT_EXCEEDED:
116  case HttpResponseCode::REQUEST_TIMEOUT:
117  case HttpResponseCode::AUTHENTICATION_TIMEOUT:
118  case HttpResponseCode::LOGIN_TIMEOUT:
119  case HttpResponseCode::GATEWAY_TIMEOUT:
120  case HttpResponseCode::NETWORK_READ_TIMEOUT:
122  return true;
123  default:
124  return false;
125  }
126  }
127 
132  {
133  public:
137  HttpResponse(const std::shared_ptr<const HttpRequest>& originatingRequest) :
138  m_httpRequest(originatingRequest),
139  m_responseCode(HttpResponseCode::REQUEST_NOT_MADE),
140  m_hasClientError(false)
141  {}
142 
143  virtual ~HttpResponse() = default;
144 
148  virtual inline const HttpRequest& GetOriginatingRequest() const { return *m_httpRequest; }
149 
153  virtual inline void SetOriginatingRequest(const std::shared_ptr<const HttpRequest>& httpRequest) { m_httpRequest = httpRequest; }
154 
158  virtual HeaderValueCollection GetHeaders() const = 0;
162  virtual bool HasHeader(const char* headerName) const = 0;
166  virtual const Aws::String& GetHeader(const Aws::String& headerName) const = 0;
170  virtual inline HttpResponseCode GetResponseCode() const { return m_responseCode; }
174  virtual inline void SetResponseCode(HttpResponseCode httpResponseCode) { m_responseCode = httpResponseCode; }
178  virtual const Aws::String& GetContentType() const { return GetHeader(Http::CONTENT_TYPE_HEADER); }
182  virtual Aws::IOStream& GetResponseBody() const = 0;
191  virtual void AddHeader(const Aws::String&, const Aws::String&) = 0;
195  virtual void SetContentType(const Aws::String& contentType) { AddHeader("content-type", contentType); }
196 
197  inline bool HasClientError() const { return m_hasClientError; }
198  inline void SetClientErrorType(Aws::Client::CoreErrors errorType) {m_hasClientError = true; m_clientErrorType = errorType;}
199  inline Aws::Client::CoreErrors GetClientErrorType() { return m_clientErrorType; }
200 
201  inline const Aws::String &GetClientErrorMessage() const { return m_clientErrorMessage; }
202  inline void SetClientErrorMessage(const Aws::String &error) { m_clientErrorMessage = error; }
203 
204  private:
205  HttpResponse(const HttpResponse&);
206  HttpResponse& operator = (const HttpResponse&);
207 
208  std::shared_ptr<const HttpRequest> m_httpRequest;
209  HttpResponseCode m_responseCode;
210  // Error generated by http client, SDK or users, indicating non service error during http request
211  bool m_hasClientError;
212  Aws::Client::CoreErrors m_clientErrorType;
213  Aws::String m_clientErrorMessage;
214  };
215 
216  } // namespace Http
217 } // namespace Aws
218 
219 
Aws::IOStream
std::basic_iostream< char, std::char_traits< char > > IOStream
Definition: AWSStreamFwd.h:22
Aws::Utils::Stream::ResponseStream
Definition: ResponseStream.h:22
AWS_CORE_API
#define AWS_CORE_API
Definition: Core_EXPORTS.h:25
CoreErrors.h
Aws::Client::CoreErrors
CoreErrors
Definition: CoreErrors.h:21
Aws::Http::HeaderValueCollection
Aws::Map< Aws::String, Aws::String > HeaderValueCollection
Definition: HttpTypes.h:53
Aws::Http::HttpResponse::SetContentType
virtual void SetContentType(const Aws::String &contentType)
Definition: HttpResponse.h:195
Aws::Http::HttpRequest
Definition: HttpRequest.h:66
Aws::Http::HttpResponse::GetResponseCode
virtual HttpResponseCode GetResponseCode() const
Definition: HttpResponse.h:170
Aws::Http::HttpResponse::HasClientError
bool HasClientError() const
Definition: HttpResponse.h:197
Aws::Http::IsRetryableHttpResponseCode
bool IsRetryableHttpResponseCode(HttpResponseCode responseCode)
Definition: HttpResponse.h:108
Aws::Http::HttpResponse
Definition: HttpResponse.h:132
Aws::Http::HttpResponse::SwapResponseStreamOwnership
virtual Utils::Stream::ResponseStream && SwapResponseStreamOwnership()=0
Aws::Http::HttpResponse::GetClientErrorMessage
const Aws::String & GetClientErrorMessage() const
Definition: HttpResponse.h:201
Aws::Http::HttpResponse::SetOriginatingRequest
virtual void SetOriginatingRequest(const std::shared_ptr< const HttpRequest > &httpRequest)
Definition: HttpResponse.h:153
Aws::Http::HttpResponse::GetHeaders
virtual HeaderValueCollection GetHeaders() const =0
Aws::Http::HttpResponseCode
HttpResponseCode
Definition: HttpResponse.h:30
Aws::Http::CONTENT_TYPE_HEADER
AWS_CORE_API const char CONTENT_TYPE_HEADER[]
Aws::Http::HttpResponse::GetResponseBody
virtual Aws::IOStream & GetResponseBody() const =0
Aws::Http::HttpResponse::SetResponseCode
virtual void SetResponseCode(HttpResponseCode httpResponseCode)
Definition: HttpResponse.h:174
AWSStreamFwd.h
HttpRequest.h
Aws::Http::HttpResponse::SetClientErrorMessage
void SetClientErrorMessage(const Aws::String &error)
Definition: HttpResponse.h:202
Aws::Http::HttpResponse::AddHeader
virtual void AddHeader(const Aws::String &, const Aws::String &)=0
Aws::Http::HttpResponse::GetContentType
virtual const Aws::String & GetContentType() const
Definition: HttpResponse.h:178
Aws::Http::HttpResponse::GetHeader
virtual const Aws::String & GetHeader(const Aws::String &headerName) const =0
Aws::Http::HttpResponse::SetClientErrorType
void SetClientErrorType(Aws::Client::CoreErrors errorType)
Definition: HttpResponse.h:198
Aws::Http::HttpResponse::GetOriginatingRequest
virtual const HttpRequest & GetOriginatingRequest() const
Definition: HttpResponse.h:148
Aws::Http::HttpResponse::HasHeader
virtual bool HasHeader(const char *headerName) const =0
Aws::Http::HttpResponse::~HttpResponse
virtual ~HttpResponse()=default
Core_EXPORTS.h
Aws
Definition: AccessManagementClient.h:15
HttpTypes.h
AWSMemory.h
Aws::String
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97
Aws::Http::HttpResponseCode::REQUEST_NOT_MADE
@ REQUEST_NOT_MADE
Aws::Http::HttpResponse::HttpResponse
HttpResponse(const std::shared_ptr< const HttpRequest > &originatingRequest)
Definition: HttpResponse.h:137
Aws::Http::HttpResponse::GetClientErrorType
Aws::Client::CoreErrors GetClientErrorType()
Definition: HttpResponse.h:199