AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
HttpResponseCode.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_HTTP_HTTPRESPONSECODE_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_HTTP_HTTPRESPONSECODE_H_
18 
19 #include <iostream>
20 #include <string>
21 
23 
24 namespace alexaClientSDK {
25 namespace avsCommon {
26 namespace utils {
27 namespace http {
28 
32 
34  SUCCESS_OK = 200,
37  // HTTP Success Accepted with no response payload.
43 
56 
63 
70 
75 
80 };
81 
90 }
91 
98 inline bool isRedirect(HTTPResponseCode code) {
99  // Not all 3xx codes are redirects and we should avoid proxy codes for security reasons. Therefore the safest way
100  // to check redirection is verifying code by code.
106 }
107 
116  switch (code) {
117  case 200:
119  case 201:
121  case 202:
123  case 204:
125  case 206:
127  case 300:
129  case 301:
131  case 302:
133  case 303:
135  case 307:
137  case 308:
139  case 400:
141  case 403:
143  case 429:
145  case 500:
147  case 503:
149  }
151  logger::LogEntry("HttpResponseCodes", __func__).d("code", code).m("Unknown HTTP response code."));
153 }
154 
161 inline int responseCodeToInt(HTTPResponseCode responseCode) {
162  return static_cast<std::underlying_type<HTTPResponseCode>::type>(responseCode);
163 }
164 
172  switch (responseCode) {
174  return "HTTP_RESPONSE_CODE_UNDEFINED";
176  return "SUCCESS_OK";
178  return "SUCCESS_CREATED";
180  return "SUCCESS_ACCEPTED";
182  return "SUCCESS_NO_CONTENT";
184  return "SUCCESS_PARTIAL_CONTENT";
186  return "SUCCESS_END_CODE";
188  return "REDIRECTION_MULTIPLE_CHOICES";
190  return "REDIRECTION_MOVED_PERMANENTLY";
192  return "REDIRECTION_FOUND";
194  return "REDIRECTION_SEE_ANOTHER";
196  return "REDIRECTION_TEMPORARY_REDIRECT";
198  return "REDIRECTION_PERMANENT_REDIRECT";
200  return "CLIENT_ERROR_BAD_REQUEST";
202  return "CLIENT_ERROR_FORBIDDEN";
204  return "CLIENT_ERROR_THROTTLING_EXCEPTION";
206  return "SERVER_ERROR_INTERNAL";
208  return "SERVER_ERROR_NOT_IMPLEMENTED";
210  return "SERVER_UNAVAILABLE";
211  }
212  logger::acsdkError(logger::LogEntry("HttpResponseCodes", __func__)
213  .d("longValue", static_cast<long>(responseCode))
214  .m("Unknown HTTP response code."));
215  return "";
216 }
217 
225 inline std::ostream& operator<<(std::ostream& os, const HTTPResponseCode& code) {
226  os << responseCodeToString(code);
227  return os;
228 }
229 
230 } // namespace http
231 } // namespace utils
232 } // namespace avsCommon
233 } // namespace alexaClientSDK
234 
235 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_HTTP_HTTPRESPONSECODE_H_
HTTP code for too many requests to the service.
Definition: HttpResponseCode.h:62
HTTP code for internal error by server for not supporting the facility requested. ...
Definition: HttpResponseCode.h:67
HTTPResponseCode
Definition: HttpResponseCode.h:29
std::string responseCodeToString(HTTPResponseCode responseCode)
Definition: HttpResponseCode.h:171
HTTP code for invalid request by user.
Definition: HttpResponseCode.h:58
::std::string string
Definition: gtest-port.h:1097
HTTP Success with partial content.
Definition: HttpResponseCode.h:42
Content can be found on another URI, and the redirect should be cached - cannot change HTTP method...
Definition: HttpResponseCode.h:55
No HTTP response received.
Definition: HttpResponseCode.h:31
HTTP code for service not available.
Definition: HttpResponseCode.h:69
Content can be found on another URI, but the redirect should not be cached - cannot change HTTP metho...
Definition: HttpResponseCode.h:53
Content moved permanently.
Definition: HttpResponseCode.h:47
First success code.
Definition: HttpResponseCode.h:72
HTTPResponseCode intToHTTPResponseCode(int code)
Definition: HttpResponseCode.h:115
See another - Should issue a GET to the other URI and assume that data was received on this request...
Definition: HttpResponseCode.h:51
Last code in redirection range.
Definition: HttpResponseCode.h:79
HTTP Success with response payload.
Definition: HttpResponseCodes.h:31
No HTTP response received.
Definition: HttpResponseCodes.h:29
bool isStatusCodeSuccess(HTTPResponseCode code)
Definition: HttpResponseCode.h:88
std::mutex m
Definition: AlexaPresentationTest.cpp:91
bool isRedirect(HTTPResponseCode code)
Definition: HttpResponseCode.h:98
HTTP code for internal error by server which didn&#39;t fulfill the request.
Definition: HttpResponseCode.h:65
HTTP Success with no response payload.
Definition: HttpResponseCode.h:40
First code in redirection range.
Definition: HttpResponseCode.h:77
int responseCodeToInt(HTTPResponseCode responseCode)
Definition: HttpResponseCode.h:161
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
HTTP Success with no response payload.
Definition: HttpResponseCodes.h:35
Content found on another URI.
Definition: HttpResponseCode.h:49
type
Definition: upload.py:443
void acsdkError(const LogEntry &entry)
std::ostream & operator<<(std::ostream &os, const HTTPResponseCode &code)
Definition: HttpResponseCode.h:225
HTTP Success with response payload.
Definition: HttpResponseCode.h:34
HTTP Success with payload accepted for processing.
Definition: HttpResponseCodes.h:33
Multiple redirection choices.
Definition: HttpResponseCode.h:45
HTTP Success with new resource created.
Definition: HttpResponseCode.h:36
HTTP code for forbidden request by user.
Definition: HttpResponseCode.h:60
LogEntry is used to compile the log entry text to log via Logger.
Definition: LogEntry.h:33
Last success code.
Definition: HttpResponseCode.h:74

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0