From f39f21b56feba79f6cda53b1da239591b7c3b3a9 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 29 Jul 2018 22:27:10 +0200 Subject: [PATCH] Minor cleanups --- client_http.hpp | 28 ++++++++++++++-------------- client_https.hpp | 2 +- utility.hpp | 2 -- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/client_http.hpp b/client_http.hpp index 5e92df0..66fd8a8 100644 --- a/client_http.hpp +++ b/client_http.hpp @@ -412,6 +412,20 @@ namespace SimpleWeb { return connection; } + std::pair parse_host_port(const std::string &host_port, unsigned short default_port) const noexcept { + std::pair parsed_host_port; + std::size_t host_end = host_port.find(':'); + if(host_end == std::string::npos) { + parsed_host_port.first = host_port; + parsed_host_port.second = default_port; + } + else { + parsed_host_port.first = host_port.substr(0, host_end); + parsed_host_port.second = static_cast(stoul(host_port.substr(host_end + 1))); + } + return parsed_host_port; + } + virtual std::shared_ptr create_connection() noexcept = 0; virtual void connect(const std::shared_ptr &) = 0; @@ -434,20 +448,6 @@ namespace SimpleWeb { return streambuf; } - std::pair parse_host_port(const std::string &host_port, unsigned short default_port) const noexcept { - std::pair parsed_host_port; - std::size_t host_end = host_port.find(':'); - if(host_end == std::string::npos) { - parsed_host_port.first = host_port; - parsed_host_port.second = default_port; - } - else { - parsed_host_port.first = host_port.substr(0, host_end); - parsed_host_port.second = static_cast(stoul(host_port.substr(host_end + 1))); - } - return parsed_host_port; - } - void write(const std::shared_ptr &session) { session->connection->set_timeout(); asio::async_write(*session->connection->socket, session->request_streambuf->data(), [this, session](const error_code &ec, std::size_t /*bytes_transferred*/) { diff --git a/client_https.hpp b/client_https.hpp index 017cbf9..a5f9f7c 100644 --- a/client_https.hpp +++ b/client_https.hpp @@ -91,7 +91,7 @@ namespace SimpleWeb { if(!ResponseMessage::parse(response->content, response->http_version, response->status_code, response->header)) session->callback(session->connection, make_error_code::make_error_code(errc::protocol_error)); else { - if(response->status_code.empty() || response->status_code.compare(0, 3, "200") != 0) + if(response->status_code.compare(0, 3, "200") != 0) session->callback(session->connection, make_error_code::make_error_code(errc::permission_denied)); else this->handshake(session); diff --git a/utility.hpp b/utility.hpp index 89fcafc..08c638b 100644 --- a/utility.hpp +++ b/utility.hpp @@ -228,7 +228,6 @@ namespace SimpleWeb { public: /// Parse request line and header fields static bool parse(std::istream &stream, std::string &method, std::string &path, std::string &query_string, std::string &version, CaseInsensitiveMultimap &header) noexcept { - header.clear(); std::string line; std::size_t method_end; if(getline(stream, line) && (method_end = line.find(' ')) != std::string::npos) { @@ -276,7 +275,6 @@ namespace SimpleWeb { public: /// Parse status line and header fields static bool parse(std::istream &stream, std::string &version, std::string &status_code, CaseInsensitiveMultimap &header) noexcept { - header.clear(); std::string line; std::size_t version_end; if(getline(stream, line) && (version_end = line.find(' ')) != std::string::npos) {