AlexaClientSDK  1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
HTTP2MimeRequestEncoder.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_HTTP2_HTTP2MIMEREQUESTENCODER_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_HTTP2_HTTP2MIMEREQUESTENCODER_H_
18 
19 #include <memory>
20 #include <ostream>
21 #include <string>
22 #include <vector>
23 
26 
27 namespace alexaClientSDK {
28 namespace avsCommon {
29 namespace utils {
30 namespace http2 {
31 
38 public:
45  HTTP2MimeRequestEncoder(const std::string& boundary, std::shared_ptr<HTTP2MimeRequestSourceInterface> source);
46 
50  ~HTTP2MimeRequestEncoder() = default;
51 
54  HTTP2SendDataResult onSendData(char* bytes, size_t size) override;
55  std::vector<std::string> getRequestHeaderLines() override;
57 
58 private:
60  enum class State {
62  NEW,
64  GETTING_1ST_PART_HEADERS,
66  SENDING_1ST_BOUNDARY,
68  SENDING_PART_HEADERS,
70  SENDING_PART_DATA,
72  SENDING_END_BOUNDARY,
74  GETTING_NTH_PART_HEADERS,
76  SENDING_CRLF_AFTER_BOUNDARY,
78  SENDING_TERMINATING_DASHES,
80  DONE,
82  ABORT
83  };
84 
85  // Friend operator<<() to enable debug output.
86  friend std::ostream& operator<<(std::ostream& stream, State state);
87 
93  void setState(State newState);
94 
106  bool sendString(char* bytes, size_t size, const std::string& text);
107 
119  bool sendStringAndCRLF(char* bytes, size_t size, const std::string& text);
120 
126  HTTP2SendDataResult continueResult();
127 
129  State m_state;
130 
132  std::string m_rawBoundary;
133 
135  std::string m_prefixedBoundary;
136 
138  std::shared_ptr<HTTP2MimeRequestSourceInterface> m_source;
139 
141  size_t m_bytesCopied;
142 
144  HTTP2GetMimeHeadersResult m_getMimeHeaderLinesResult;
145 
147  std::vector<std::string>::const_iterator m_headerLine;
148 
150  size_t m_stringIndex;
151 };
152 
153 } // namespace http2
154 } // namespace utils
155 } // namespace avsCommon
156 } // namespace alexaClientSDK
157 
158 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_HTTP2_HTTP2MIMEREQUESTENCODER_H_
HTTP2MimeRequestEncoder(const std::string &boundary, std::shared_ptr< HTTP2MimeRequestSourceInterface > source)
Definition: HTTP2MimeRequestEncoder.cpp:76
HTTP2SendDataResult onSendData(char *bytes, size_t size) override
Definition: HTTP2MimeRequestEncoder.cpp:88
std::vector< std::string > getRequestHeaderLines() override
Definition: HTTP2MimeRequestEncoder.cpp:242
Data not received. Abort receiving further data for this response.
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
friend std::ostream & operator<<(std::ostream &stream, State state)
Definition: HTTP2MimeRequestEncoder.cpp:48

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