diff options
author | Oleg Morozenkov <omorozenkov@gmail.com> | 2015-07-29 14:45:45 +0300 |
---|---|---|
committer | Oleg Morozenkov <omorozenkov@gmail.com> | 2015-07-29 14:45:45 +0300 |
commit | 99072def67e54d664edd96b9c0f124c4f09cedee (patch) | |
tree | b34ce972e87686b27f6d66ffaa31b079aa0b52d7 /src/tgbot/net/HttpClient.cpp | |
parent | f69b2ac4ff123e0fb8b335fe28f6de4242c4f396 (diff) |
Fix includes + fix some minor bugs
Diffstat (limited to 'src/tgbot/net/HttpClient.cpp')
-rw-r--r-- | src/tgbot/net/HttpClient.cpp | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/src/tgbot/net/HttpClient.cpp b/src/tgbot/net/HttpClient.cpp deleted file mode 100644 index fefeac5..0000000 --- a/src/tgbot/net/HttpClient.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2015 Oleg Morozenkov - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "HttpClient.h" - -#include <boost/asio/ssl.hpp> - -using namespace std; -using namespace boost::asio; -using namespace boost::asio::ip; -using namespace boost::asio::local; - -namespace TgBot { - -HttpClient& HttpClient::getInstance() { - static HttpClient result; - return result; -} - -string HttpClient::makeRequest(const Url& url, const vector<HttpReqArg>& args) { - ssl::context context(ssl::context::sslv23); - context.set_default_verify_paths(); - - ssl::stream<tcp::socket> socket(_ioService, context); - tcp::resolver resolver(_ioService); - tcp::resolver::query query(url.host, url.protocol); - - connect(socket.lowest_layer(), resolver.resolve(query)); - -// boost::asio::socket_base::keep_alive keepAliveOption(true); -// socket.lowest_layer().set_option(keepAliveOption); - - socket.set_verify_mode(ssl::verify_none); - socket.set_verify_callback(ssl::rfc2818_verification(url.host)); - socket.handshake(ssl::stream<tcp::socket>::client); - - string requestText = HttpParser::getInstance().generateRequest(url, args, false); - write(socket, buffer(requestText.c_str(), requestText.length())); - - string response; - char buff[1024]; - boost::system::error_code error; - while (!error) { - size_t bytes = read(socket, buffer(buff), error); - response += string(buff, bytes); - printf("%s", string(buff, bytes).c_str()); - } - - return HttpParser::getInstance().parseResponse(response); -} - -} |