From 7cae5f897b073f3b8e68cdf512e3b5d6b418c219 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 12 Dec 2007 19:29:19 +0000 Subject: [PATCH] fixed http_connection error handling and improved http parser --- src/http_connection.cpp | 12 +++++++++++- src/http_tracker_connection.cpp | 6 +++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/http_connection.cpp b/src/http_connection.cpp index 7ca2c87b5..8d8de6723 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -285,7 +285,17 @@ void http_connection::on_read(asio::error_code const& e { libtorrent::buffer::const_interval rcv_buf(&m_recvbuffer[0] , &m_recvbuffer[0] + m_read_pos); - m_parser.incoming(rcv_buf); + try + { + m_parser.incoming(rcv_buf); + } + catch (std::exception& e) + { + m_timer.cancel(); + m_handler(asio::error::fault, m_parser, 0, 0); + m_handler.clear(); + return; + } if (!m_bottled && m_parser.header_finished()) { if (m_read_pos > m_parser.body_start()) diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index 91c305d17..505d8ffb2 100755 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -204,7 +204,11 @@ namespace libtorrent char dummy; std::string bytes; size_type range_start, range_end; - range_str >> bytes >> range_start >> dummy >> range_end; + // apparently some web servers do not send the "bytes" + // in their content-range + if (value.find(' ') != std::string::npos) + range_str >> bytes; + range_str >> range_start >> dummy >> range_end; if (!range_str || range_end < range_start) { throw std::runtime_error("invalid content-range in HTTP response: " + range_str.str());