AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
HTTPContent.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_HTTPCONTENT_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_HTTPCONTENT_H_
18 
19 #include <chrono>
20 #include <future>
21 #include <memory>
22 #include <string>
23 
25 
26 namespace alexaClientSDK {
27 namespace avsCommon {
28 namespace utils {
29 
34 class HTTPContent {
35 public:
44  std::future<long> httpStatusCode,
45  std::future<std::string> httpContentType,
46  std::shared_ptr<avsCommon::avs::attachment::InProcessAttachment> stream);
47 
54  bool isStatusCodeSuccess();
55 
61  long getStatusCode();
62 
69  bool isReady(const std::chrono::milliseconds timeout) const;
70 
77 
83  std::shared_ptr<avsCommon::avs::attachment::InProcessAttachment> getDataStream();
84 
85 private:
87  mutable std::shared_future<long> m_statusCode;
88 
90  std::shared_future<std::string> m_contentType;
91 
93  std::shared_ptr<avsCommon::avs::attachment::InProcessAttachment> m_dataStream;
94 };
95 
97  std::future<long> httpStatusCode,
98  std::future<std::string> httpContentType,
99  std::shared_ptr<avsCommon::avs::attachment::InProcessAttachment> stream) :
100  m_statusCode{std::move(httpStatusCode)},
101  m_contentType{std::move(httpContentType)},
102  m_dataStream{stream} {};
103 
105  auto statusCodeFuture = m_statusCode;
106  return statusCodeFuture.get();
107 }
108 
110  auto statusCode = getStatusCode();
111  return (statusCode >= 200) && (statusCode < 300);
112 }
113 
114 inline bool HTTPContent::isReady(const std::chrono::milliseconds timeout) const {
115  auto statusCodeFuture = m_statusCode;
116  auto status = statusCodeFuture.wait_for(timeout);
117  return std::future_status::ready == status;
118 }
119 
121  auto contentTypeFuture = m_contentType;
122  return contentTypeFuture.get();
123 }
124 
125 inline std::shared_ptr<avsCommon::avs::attachment::InProcessAttachment> HTTPContent::getDataStream() {
126  return m_dataStream;
127 }
128 
129 } // namespace utils
130 } // namespace avsCommon
131 } // namespace alexaClientSDK
132 
133 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_HTTPCONTENT_H_
std::shared_ptr< avsCommon::avs::attachment::InProcessAttachment > getDataStream()
Definition: HTTPContent.h:125
::std::string string
Definition: gtest-port.h:1097
std::string getContentType()
Definition: HTTPContent.h:120
bool isReady(const std::chrono::milliseconds timeout) const
Definition: HTTPContent.h:114
HTTPContent(std::future< long > httpStatusCode, std::future< std::string > httpContentType, std::shared_ptr< avsCommon::avs::attachment::InProcessAttachment > stream)
Definition: HTTPContent.h:96
bool isStatusCodeSuccess()
Definition: HTTPContent.h:109
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
long getStatusCode()
Definition: HTTPContent.h:104
const T & move(const T &t)
Definition: gtest-port.h:1317

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