@@ -354,7 +354,10 @@ namespace boost { namespace network { namespace http { namespace impl {
354
354
this ->part .begin ()
355
355
, bytes_transferred
356
356
);
357
- this ->body_promise .set_value (body_string);
357
+ if (this ->is_chunk_encoding )
358
+ this ->body_promise .set_value (parse_chunk_encoding (body_string));
359
+ else
360
+ this ->body_promise .set_value (body_string);
358
361
}
359
362
// TODO set the destination value somewhere!
360
363
this ->destination_promise .set_value (" " );
@@ -428,6 +431,34 @@ namespace boost { namespace network { namespace http { namespace impl {
428
431
}
429
432
}
430
433
}
434
+
435
+ string_type parse_chunk_encoding ( string_type & body_string ) {
436
+ string_type body;
437
+ string_type crlf = " \r\n " ;
438
+
439
+ typename string_type::iterator begin = body_string.begin ();
440
+ for (typename string_type::iterator iter =
441
+ std::search (begin, body_string.end (), crlf.begin (), crlf.end ());
442
+ iter != body_string.end ();
443
+ iter = std::search (begin, body_string.end (), crlf.begin (), crlf.end ())) {
444
+ string_type line (begin, iter);
445
+ if (line.empty ())
446
+ break ;
447
+ std::stringstream stream (line);
448
+ int len;
449
+ stream >> std::hex >> len;
450
+ std::advance (iter, 2 );
451
+ if (!len)
452
+ break ;
453
+ if (len <= body_string.end () - iter) {
454
+ body.insert (body.end (), iter, iter + len);
455
+ std::advance (iter, len);
456
+ }
457
+ begin = iter;
458
+ }
459
+
460
+ return body;
461
+ }
431
462
432
463
bool follow_redirect_;
433
464
resolver_type & resolver_;
0 commit comments