You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because of #2392, I've added the r.headers.remove(name: "content-length") to this echo server below:
import Vapor
varenv=tryEnvironment.detect()tryLoggingSystem.bootstrap(from:&env)letapp=Application(env)defer{ app.shutdown()}
app.on(.POST,"echo"){ request ->Responseinletr=Response(body:.init(stream:{ writer in
request.body.drain{ body in
switch body {case.buffer(let buffer):return writer.write(.buffer(buffer))case.error(let error):return writer.write(.error(error))case.end:return writer.write(.end)}}}, count:0))
r.headers.remove(name:"content-length")return r
}try app.run()
I would expect this to stream. To check that it does, I wrote this shell script:
which writes the request head + the first three bytes (FOO), then waits a second until it writes the next three bytes (BAR). Sure, HTTP chunks aren't semantic but 1 second should really be long enough for them to be sent back individually (and not concatenated).
They're sent back concatenated which means that Vapor must buffer them in memory!?
Expected:
HTTP/1.1 200 OK
connection: keep-alive
date: Wed, 10 Jun 2020 22:40:08 GMT
transfer-encoding: chunked
3\r\n
FOO\r\n
3\r\n
BAR\r\n
0
Actual:
HTTP/1.1 200 OK
connection: keep-alive
date: Wed, 10 Jun 2020 22:40:08 GMT
transfer-encoding: chunked
6
FOOBAR
0
I know that this is totally legal for Vapor to do but given that I waited a whole second, I would have really expected for those bytes to come back in two chunks.
However, even with body streaming enabled, Vapor doesn't currently allow for a response to be sent before the current request has been entirely consumed. I've started a PR to tackle this issue here: #2404
Because of #2392, I've added the
r.headers.remove(name: "content-length")
to this echo server below:I would expect this to stream. To check that it does, I wrote this shell script:
which writes the request head + the first three bytes (
FOO
), then waits a second until it writes the next three bytes (BAR
). Sure, HTTP chunks aren't semantic but 1 second should really be long enough for them to be sent back individually (and not concatenated).They're sent back concatenated which means that Vapor must buffer them in memory!?
Expected:
Actual:
I know that this is totally legal for Vapor to do but given that I waited a whole second, I would have really expected for those bytes to come back in two chunks.
For a
.pcap
runAnother way of showing this would be
where I only write the first chunk, and then wait 100 seconds. Sure, the "client" never completes the request but the
FOO
should've been replied back.The text was updated successfully, but these errors were encountered: