fixed http_connection error handling and improved http parser

This commit is contained in:
Arvid Norberg 2007-12-12 19:29:19 +00:00
parent b2dc035a54
commit 7cae5f897b
2 changed files with 16 additions and 2 deletions

View File

@ -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())

View File

@ -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());