mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
bugfixes and tests for new http istream consume
This commit is contained in:
@@ -829,7 +829,7 @@ BOOST_AUTO_TEST_CASE( plain_http_response ) {
|
||||
BOOST_CHECK( r.get_body() == "<!doctype html>\n<html>\n<head>\n<title>Thor</title>\n</head>\n<body> \n<p>Thor</p>\n</body>" );
|
||||
}
|
||||
|
||||
/*BOOST_AUTO_TEST_CASE( parse_istream ) {
|
||||
BOOST_AUTO_TEST_CASE( parse_istream ) {
|
||||
websocketpp::http::parser::response r;
|
||||
|
||||
std::stringstream s;
|
||||
@@ -846,10 +846,11 @@ BOOST_AUTO_TEST_CASE( plain_http_response ) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == false );
|
||||
BOOST_CHECK( pos == 405 );
|
||||
BOOST_CHECK( r.headers_ready() == true );
|
||||
}*/
|
||||
BOOST_CHECK_EQUAL( exception, false );
|
||||
BOOST_CHECK_EQUAL( pos, 405 );
|
||||
BOOST_CHECK_EQUAL( r.headers_ready(), true );
|
||||
BOOST_CHECK_EQUAL( r.ready(), true );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( write_request_basic ) {
|
||||
websocketpp::http::parser::request r;
|
||||
@@ -888,6 +889,5 @@ BOOST_AUTO_TEST_CASE( write_request_with_body ) {
|
||||
r.replace_header("Content-Type","application/x-www-form-urlencoded");
|
||||
r.set_body("licenseID=string&content=string¶msXML=string");
|
||||
|
||||
std::cout << r.raw() << std::endl;
|
||||
BOOST_CHECK( r.raw() == raw );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,9 @@ namespace http {
|
||||
// Maximum size in bytes before rejecting an HTTP header as too big.
|
||||
const size_t max_header_size = 16000;
|
||||
|
||||
// Number of bytes to use for temporary istream read buffers
|
||||
const size_t istream_buffer = 512;
|
||||
|
||||
// invalid HTTP token characters
|
||||
// 0x00 - 0x32, 0x7f-0xff
|
||||
// ( ) < > @ , ; : \ " / [ ] ? = { }
|
||||
|
||||
@@ -132,15 +132,15 @@ inline size_t response::consume(const char *buf, size_t len) {
|
||||
}
|
||||
|
||||
inline size_t response::consume(std::istream & s) {
|
||||
char buf[512];
|
||||
char buf[istream_buffer];
|
||||
size_t bytes_read;
|
||||
size_t bytes_processed;
|
||||
size_t total = 0;
|
||||
|
||||
while (s.good()) {
|
||||
s.getline(buf,512);
|
||||
s.getline(buf,istream_buffer);
|
||||
bytes_read = s.gcount();
|
||||
|
||||
|
||||
if (s.fail() || s.eof()) {
|
||||
bytes_processed = this->consume(buf,bytes_read);
|
||||
total += bytes_processed;
|
||||
@@ -156,8 +156,7 @@ inline size_t response::consume(std::istream & s) {
|
||||
// the delimiting newline was found. Replace the trailing null with
|
||||
// the newline that was discarded, since our raw consume function
|
||||
// expects the newline to be be there.
|
||||
buf[bytes_read] = '\n';
|
||||
bytes_read++;
|
||||
buf[bytes_read-1] = '\n';
|
||||
bytes_processed = this->consume(buf,bytes_read);
|
||||
total += bytes_processed;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user