AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
HTTPContentFetcherInterface.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_SDKINTERFACES_INCLUDE_AVSCOMMON_SDKINTERFACES_HTTPCONTENTFETCHERINTERFACE_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_SDKINTERFACES_INCLUDE_AVSCOMMON_SDKINTERFACES_HTTPCONTENTFETCHERINTERFACE_H_
18 
19 #include <memory>
20 
23 #include <AVSCommon/Utils/SDKVersion.h>
24 
25 namespace alexaClientSDK {
26 namespace avsCommon {
27 namespace sdkInterfaces {
28 
33 public:
35  enum class FetchOptions {
40  };
41 
43  enum class State {
45  INITIALIZED,
47  FETCHING_HEADER,
49  HEADER_DONE,
51  FETCHING_BODY,
53  BODY_DONE,
55  ERROR
56  };
57 
62  struct Header {
66  bool successful;
72  ssize_t contentLength;
73 
74  Header() :
75  successful(false),
76  responseCode(avsCommon::utils::http::HTTPResponseCode::HTTP_RESPONSE_CODE_UNDEFINED),
77  contentType(""),
78  contentLength(0) {
79  }
80  };
81 
85  virtual ~HTTPContentFetcherInterface() = default;
86 
93  virtual State getState() = 0;
94 
100  virtual std::string getUrl() const = 0;
101 
110  virtual std::string getEffectiveUrl() const = 0;
111 
121  virtual Header getHeader(std::atomic<bool>* shouldShutdown) = 0;
122 
130  virtual bool getBody(std::shared_ptr<avsCommon::avs::attachment::AttachmentWriter> writer) = 0;
131 
135  virtual void shutdown() = 0;
136 
145  virtual std::unique_ptr<avsCommon::utils::HTTPContent> getContent(
146  FetchOptions option,
147  std::unique_ptr<avsCommon::avs::attachment::AttachmentWriter> writer = nullptr,
148  const std::vector<std::string>& customHeaders = std::vector<std::string>()) = 0;
149 
155  static std::string getUserAgent();
156 
162  static std::string stateToString(State state);
163 };
164 
166  return "AvsDeviceSdk/" + utils::sdkVersion::getCurrentVersion();
167 }
168 
170  switch (state) {
171  case State::INITIALIZED:
172  return "INITIALIZED";
174  return "FETCHING_HEADER";
175  case State::HEADER_DONE:
176  return "HEADER_DONE";
178  return "FETCHING_BODY";
179  case State::BODY_DONE:
180  return "BODY_DONE";
181  case State::ERROR:
182  return "ERROR";
183  }
184  return "";
185 }
186 
194 inline std::ostream& operator<<(std::ostream& os, const HTTPContentFetcherInterface::State& state) {
196  return os;
197 }
198 
199 } // namespace sdkInterfaces
200 } // namespace avsCommon
201 } // namespace alexaClientSDK
202 
203 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_SDKINTERFACES_INCLUDE_AVSCOMMON_SDKINTERFACES_HTTPCONTENTFETCHERINTERFACE_H_
std::ostream & operator<<(std::ostream &stream, const AudioInputProcessorObserverInterface::State &state)
Definition: AudioInputProcessorObserverInterface.h:94
HTTPResponseCode
Definition: HttpResponseCode.h:29
::std::string string
Definition: gtest-port.h:1097
virtual std::unique_ptr< avsCommon::utils::HTTPContent > getContent(FetchOptions option, std::unique_ptr< avsCommon::avs::attachment::AttachmentWriter > writer=nullptr, const std::vector< std::string > &customHeaders=std::vector< std::string >())=0
Done fetching the body. At this point the content fetcher can only be used to read the headers...
static std::string getUserAgent()
Definition: HTTPContentFetcherInterface.h:165
avsCommon::utils::http::HTTPResponseCode responseCode
The HTTP status code received.
Definition: HTTPContentFetcherInterface.h:68
No HTTP response received.
Definition: HttpResponseCodes.h:29
Some error happened at any stage and the content fetcher cannot be used anymore.
HTTPResponseCode
Definition: HttpResponseCodes.h:27
State
The state of payload fetching.
Definition: HTTPContentFetcherInterface.h:43
virtual Header getHeader(std::atomic< bool > *shouldShutdown)=0
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
FetchOptions
Represents what HTTP content to fetch.
Definition: HTTPContentFetcherInterface.h:35
virtual bool getBody(std::shared_ptr< avsCommon::avs::attachment::AttachmentWriter > writer)=0
ssize_t contentLength
The value of the Content-Length HTTP header.
Definition: HTTPContentFetcherInterface.h:72
Done fetching the header. Ready to start fetching the body.
static std::string stateToString(State state)
Definition: HTTPContentFetcherInterface.h:169
std::string contentType
The value of the Content-Type HTTP header.
Definition: HTTPContentFetcherInterface.h:70
static std::string getCurrentVersion()
Definition: SDKVersion.h.in:31

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