- Notifications
You must be signed in to change notification settings - Fork425
Make http client connection buffer size configurable#843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -38,19 +38,20 @@ namespace network { | ||
namespace http { | ||
namespace impl { | ||
template <classbuffer_type> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I don't think this change is necessary... unless I'm missing something. We're using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. My thought was that I didn't want to redefine the buffer_type in the parser, which is just a helper class. The actual buffer type is defined in the class utilizing the parser, and then just forwarded. IMHO it was redundancy introduced by mistake which enforced redefinition of exactly the same buffer type in a helper class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. True, but not in the way it's designed to use traits to dispatch on the tag. Arguably the problem is that we're hard-coding the type of the buffer instead of using the tag-based dispatch we've been using everywhere. Because this is currently an implementation detail, I think the way you've done it is fine -- but that we might want to think about the wider design of this, so that it can be applied more systematically. At this point, since the tests pass I'm willing to merge this as-is, but something worth thinking about in the future to clean this up better. | ||
struct chunk_encoding_parser { | ||
typedef typename buffer_type::const_iterator const_iterator; | ||
typedef boost::iterator_range<const_iterator> char_const_range; | ||
chunk_encoding_parser() : state(state_t::header), chunk_size(0) {} | ||
enum class state_t { header, header_end, data, data_end }; | ||
state_t state; | ||
size_t chunk_size; | ||
buffer_type buffer; | ||
void update_chunk_size(char_const_range const &range) { | ||
if (range.empty()) return; | ||
std::stringstream ss; | ||
ss << std::hex << range; | ||
@@ -60,11 +61,7 @@ struct chunk_encoding_parser { | ||
chunk_size = (chunk_size << (range.size() * 4)) | size; | ||
} | ||
char_const_range operator()(char_const_range const &range) { | ||
auto iter = boost::begin(range); | ||
auto begin = iter; | ||
auto pos = boost::begin(buffer); | ||
@@ -147,6 +144,7 @@ struct http_async_connection | ||
typedef typename delegate_factory<Tag>::type delegate_factory_type; | ||
typedef typename delegate_factory_type::connection_delegate_ptr | ||
connection_delegate_ptr; | ||
typedef chunk_encoding_parser<typename protocol_base::buffer_type> chunk_encoding_parser_type; | ||
http_async_connection(resolver_type& resolver, resolve_function resolve, | ||
bool follow_redirect, int timeout, | ||
@@ -484,13 +482,14 @@ struct http_async_connection | ||
} else { | ||
string_type body_string; | ||
if (this->is_chunk_encoding && remove_chunk_markers_) { | ||
const auto parse_buffer_size = parse_chunk_encoding.buffer.size(); | ||
for (size_t i = 0; i < this->partial_parsed.size(); i += parse_buffer_size) { | ||
auto range = parse_chunk_encoding(boost::make_iterator_range( | ||
static_cast< | ||
typename chunk_encoding_parser_type::const_iterator>(this->partial_parsed.data()) + i, | ||
static_cast< | ||
typename chunk_encoding_parser_type::const_iterator>(this->partial_parsed.data()) + | ||
std::min(i +parse_buffer_size, this->partial_parsed.size()))); | ||
body_string.append(boost::begin(range), boost::end(range)); | ||
} | ||
this->partial_parsed.clear(); | ||
@@ -602,7 +601,7 @@ struct http_async_connection | ||
connection_delegate_ptr delegate_; | ||
boost::asio::streambuf command_streambuf; | ||
string_type method; | ||
chunk_encoding_parser_type parse_chunk_encoding; | ||
}; | ||
} // namespace impl | ||