From e6a3205e18be92f40a2c34de3ef36a4906d14dca Mon Sep 17 00:00:00 2001 From: eidheim Date: Thu, 26 Nov 2015 14:29:43 +0100 Subject: [PATCH] Improved Client::parse_response_header, and simplified endpoint code in Server::start. --- client_http.hpp | 21 ++++++++++++--------- server_http.hpp | 10 +++++----- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/client_http.hpp b/client_http.hpp index 1fe5c1f..6c7e269 100644 --- a/client_http.hpp +++ b/client_http.hpp @@ -148,20 +148,23 @@ namespace SimpleWeb { getline(stream, line); size_t version_end=line.find(' '); if(version_end!=std::string::npos) { - response->http_version=line.substr(5, version_end-5); - response->status_code=line.substr(version_end+1, line.size()-version_end-2); + if(5http_version=line.substr(5, version_end-5); + if((version_end+1)status_code=line.substr(version_end+1, line.size()-(version_end+1)-1); getline(stream, line); - size_t param_end=line.find(':'); - while(param_end!=std::string::npos) { + size_t param_end; + while((param_end=line.find(':'))!=std::string::npos) { size_t value_start=param_end+1; - if(line[value_start]==' ') - value_start++; - - response->header[line.substr(0, param_end)]=line.substr(value_start, line.size()-value_start-1); + if((value_start)header.insert(std::make_pair(line.substr(0, param_end), line.substr(value_start, line.size()-value_start-1))); + } getline(stream, line); - param_end=line.find(':'); } } } diff --git a/server_http.hpp b/server_http.hpp index 968ff96..76010b8 100644 --- a/server_http.hpp +++ b/server_http.hpp @@ -137,14 +137,14 @@ namespace SimpleWeb { if(io_service.stopped()) io_service.reset(); - std::unique_ptr endpoint; + boost::asio::ip::tcp::endpoint endpoint; if(config.address.size()>0) - endpoint=std::unique_ptr(new boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(config.address), config.port)); + endpoint=boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(config.address), config.port); else - endpoint=std::unique_ptr(new boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), config.port)); - acceptor.open(endpoint->protocol()); + endpoint=boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), config.port); + acceptor.open(endpoint.protocol()); acceptor.set_option(boost::asio::socket_base::reuse_address(config.reuse_address)); - acceptor.bind(*endpoint); + acceptor.bind(endpoint); acceptor.listen(); accept();