merged unit test from RC_1_0
This commit is contained in:
parent
9a2e511dda
commit
7e69239991
|
@ -146,7 +146,7 @@ private:
|
|||
, error_code const& e);
|
||||
void on_assign_bandwidth(error_code const& e);
|
||||
|
||||
void callback(error_code e, char const* data = 0, int size = 0);
|
||||
void callback(error_code e, char* data = 0, int size = 0);
|
||||
|
||||
std::vector<char> m_recvbuffer;
|
||||
|
||||
|
|
|
@ -670,7 +670,7 @@ void http_connection::on_connect(error_code const& e)
|
|||
}
|
||||
}
|
||||
|
||||
void http_connection::callback(error_code e, char const* data, int size)
|
||||
void http_connection::callback(error_code e, char* data, int size)
|
||||
{
|
||||
if (m_bottled && m_called) return;
|
||||
|
||||
|
@ -779,11 +779,11 @@ void http_connection::on_read(error_code const& e
|
|||
{
|
||||
error_code ec = asio::error::eof;
|
||||
TORRENT_ASSERT(bytes_transferred == 0);
|
||||
char const* data = 0;
|
||||
char* data = 0;
|
||||
std::size_t size = 0;
|
||||
if (m_bottled && m_parser.header_finished())
|
||||
{
|
||||
data = m_parser.get_body().begin;
|
||||
data = &m_recvbuffer[0] + m_parser.body_start();
|
||||
size = m_parser.get_body().left();
|
||||
}
|
||||
callback(ec, data, size);
|
||||
|
@ -865,7 +865,7 @@ void http_connection::on_read(error_code const& e
|
|||
{
|
||||
error_code ec;
|
||||
m_timer.cancel(ec);
|
||||
callback(e, m_parser.get_body().begin, m_parser.get_body().left());
|
||||
callback(e, &m_recvbuffer[0] + m_parser.body_start(), m_parser.get_body().left());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -316,6 +316,29 @@ int test_main()
|
|||
TEST_EQUAL(parser.headers().find("test2")->second, "bar");
|
||||
}
|
||||
|
||||
// test chunked encoding
|
||||
|
||||
parser.reset();
|
||||
|
||||
char const* chunked_input =
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Transfer-Encoding: chunked\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"4\r\ntest\r\n4\r\n1234\r\n10\r\n0123456789abcdef\r\n"
|
||||
"0\r\n\r\n";
|
||||
received = feed_bytes(parser, chunked_input);
|
||||
|
||||
TEST_EQUAL(strlen(chunked_input), 24 + 94)
|
||||
TEST_CHECK(received == make_tuple(24, 94, false));
|
||||
TEST_CHECK(parser.finished());
|
||||
|
||||
char mutable_buffer[100];
|
||||
memcpy(mutable_buffer, parser.get_body().begin, parser.get_body().left());
|
||||
int len = parser.collapse_chunk_headers(mutable_buffer, parser.get_body().left());
|
||||
|
||||
TEST_CHECK(std::equal(mutable_buffer, mutable_buffer + len, "test12340123456789abcdef"));
|
||||
|
||||
// test url parsing
|
||||
|
||||
error_code ec;
|
||||
|
|
Loading…
Reference in New Issue