@@ -297,28 +297,36 @@ operator()(route_params& rp) const
297297 // Calculate how much to send
298298 std::int64_t remaining = info.range_end - info.range_start + 1 ;
299299
300- // Stream file content
301- constexpr std::size_t buf_size = 16384 ;
302- char buffer[buf_size];
303-
300+ // Stream file content using serializer's internal buffer
304301 while (remaining > 0 )
305302 {
303+ capy::mutable_buffer arr[1 ];
304+ auto bufs = rp.res_body .prepare (arr);
305+ if (bufs.empty ())
306+ {
307+ auto [ec2] = co_await rp.res_body .commit (0 );
308+ if (ec2)
309+ co_return route_error (ec2);
310+ continue ;
311+ }
312+
306313 auto const to_read = static_cast <std::size_t >(
307- (std::min)(remaining, static_cast <std::int64_t >(buf_size)));
314+ (std::min)(remaining,
315+ static_cast <std::int64_t >(bufs[0 ].size ())));
308316
309- auto const n1 = f.read (buffer, to_read, ec);
310- if (ec.failed () || n1 == 0 )
317+ auto const n1 = f.read (bufs[0 ].data (), to_read, ec);
318+ if (ec.failed ())
319+ co_return route_error (ec);
320+ if (n1 == 0 )
311321 break ;
312322
313- auto [ec2, n2] = co_await rp.res_body .write (
314- capy::const_buffer (buffer, n1));
315- (void )n2;
323+ auto [ec2] = co_await rp.res_body .commit (n1);
316324 if (ec2)
317325 co_return route_error (ec2);
318326 remaining -= static_cast <std::int64_t >(n1);
319327 }
320328
321- auto [ec3] = co_await rp.res_body .write_eof ( );
329+ auto [ec3] = co_await rp.res_body .commit_eof ( 0 );
322330 if (ec3)
323331 co_return route_error (ec3);
324332 co_return route_done;
0 commit comments