AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
HttpPost.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_LIBCURLUTILS_HTTPPOST_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_LIBCURLUTILS_HTTPPOST_H_
18 
19 #include <chrono>
20 #include <curl/curl.h>
21 #include <iostream>
22 #include <memory>
23 #include <mutex>
24 #include <string>
25 
28 
29 namespace alexaClientSDK {
30 namespace avsCommon {
31 namespace utils {
32 namespace libcurlUtils {
33 
35 class HttpPost : public HttpPostInterface {
36 public:
42  static std::unique_ptr<HttpPostInterface> createHttpPostInterface();
43 
50  static std::unique_ptr<HttpPost> create();
51 
55  ~HttpPost() = default;
56 
62  HttpPost(const HttpPost& rhs) = delete;
63 
70  HttpPost& operator=(const HttpPost& rhs) = delete;
71 
72  long doPost(const std::string& url, const std::string& data, std::chrono::seconds timeout, std::string& body)
73  override;
74 
76  const std::string& url,
77  const std::vector<std::string> headerLines,
78  const std::vector<std::pair<std::string, std::string>>& data,
79  std::chrono::seconds timeout) override;
80 
82  const std::string& url,
83  const std::vector<std::string> headerLines,
84  const std::string& data,
85  std::chrono::seconds timeout) override;
86 
87 private:
91  HttpPost() = default;
92 
93  HTTPResponse doPostInternal(
95  const std::string& url,
96  const std::vector<std::string> headerLines,
97  const std::string& data,
98  std::chrono::seconds timeout);
99 
107  std::string buildPostData(CurlEasyHandleWrapper& curl, const std::vector<std::pair<std::string, std::string>>& data)
108  const;
109 
120  static size_t staticWriteCallbackLocked(char* ptr, size_t size, size_t nmemb, void* userdata);
121 
123  std::string m_bodyAccumulator;
124 };
125 
126 } // namespace libcurlUtils
127 } // namespace utils
128 } // namespace avsCommon
129 } // namespace alexaClientSDK
130 
131 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_LIBCURLUTILS_HTTPPOST_H_
static std::unique_ptr< HttpPostInterface > createHttpPostInterface()
~HttpPost()=default
::std::string string
Definition: gtest-port.h:1097
HttpPost & operator=(const HttpPost &rhs)=delete
long doPost(const std::string &url, const std::string &data, std::chrono::seconds timeout, std::string &body) override
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
static std::unique_ptr< HttpPost > create()
LIBCURL based implementation of HttpPostInterface.
Definition: HttpPost.h:35
Minimal interface for making Http POST requests.
Definition: HttpPostInterface.h:32

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