@@ -56,38 +56,30 @@ bool HTTPChunkedReadBuffer::nextImpl()
5656 if (!in)
5757 return false ;
5858
59- try
59+ // / The footer of previous chunk.
60+ if (count ())
61+ readChunkFooter ();
62+
63+ size_t chunk_size = readChunkHeader ();
64+ if (0 == chunk_size)
65+ {
66+ readChunkFooter ();
67+ in.reset (); // prevent double-eof situation.
68+ return false ;
69+ }
70+
71+ if (in->available () >= chunk_size)
6072 {
61- // / The footer of previous chunk.
62- if (count ())
63- readChunkFooter ();
64-
65- size_t chunk_size = readChunkHeader ();
66- if (0 == chunk_size)
67- {
68- readChunkFooter ();
69- in.reset (); // prevent double-eof situation.
70- return false ;
71- }
72-
73- if (in->available () >= chunk_size)
74- {
75- // / Zero-copy read from input.
76- working_buffer = Buffer (in->position (), in->position () + chunk_size);
77- in->position () += chunk_size;
78- }
79- else
80- {
81- // / Chunk is not completely in buffer, copy it to scratch space.
82- memory.resize (chunk_size);
83- in->readStrict (memory.data (), chunk_size);
84- working_buffer = Buffer (memory.data (), memory.data () + chunk_size);
85- }
73+ // / Zero-copy read from input.
74+ working_buffer = Buffer (in->position (), in->position () + chunk_size);
75+ in->position () += chunk_size;
8676 }
87- catch (...)
77+ else
8878 {
89- in.reset ();
90- throw ;
79+ // / Chunk is not completely in buffer, copy it to scratch space.
80+ memory.resize (chunk_size);
81+ in->readStrict (memory.data (), chunk_size);
82+ working_buffer = Buffer (memory.data (), memory.data () + chunk_size);
9183 }
9284
9385 // / NOTE: We postpone reading the footer to the next iteration, because it may not be completely in buffer,
0 commit comments