Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't flush on every body part #214

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/AsyncHTTPClient/HTTPHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -767,9 +767,10 @@ extension TaskHandler: ChannelDuplexHandler {

return body.stream(HTTPClient.Body.StreamWriter { part in
context.eventLoop.assertInEventLoop()
return context.writeAndFlush(self.wrapOutboundOut(.body(part))).map {
context.write(self.wrapOutboundOut(.body(part))).whenSuccess {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, this would now never flush any body which means we'll load the whole body into memory before sending.

I think the right thing to do is:

  • if you know that whole body straight away (without streaming), then we should do
    write(.head), .write(.body), .write(end), flush
  • if we actually want to stream the body, then
    writeAndFlush(.head), writeAndFlush(.body), writeAndFlush(.end)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need a test actually that shows that this PR doesn't work. We should have a test which checks that body chunks do arrive at the other end before the next bit is sent out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrote #219 to test this. This PR should go in after #219 to prove that it works.

self.callOutToDelegateFireAndForget(value: part, self.delegate.didSendRequestPart)
}
return context.eventLoop.makeSucceededFuture(())
})
}

Expand Down