-
Notifications
You must be signed in to change notification settings - Fork 621
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
Handle unread body from request #186
Conversation
http/server.ts
Outdated
@@ -271,6 +340,10 @@ export class ServerRequest { | |||
} | |||
|
|||
await this.w.flush(); | |||
|
|||
if (!this._shouldReuseConnection()) { | |||
this.conn.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ry you said that closeWriteAndWait
is what we need. I don't fully understand it's purpose. Could you follow up?
I'll wait on #188 before finishing this |
I've tried to rebase my branch against master, but given latest changes in #188 it's pretty hard. Main loop in for (const { req, conn } of queueToProcess) {
if (req) {
const res = createResponder(conn);
yield { req, res };
}
serveConn(env, conn);
} request and response are completely decoupled, which gives no easy way to check if request's body was fully read before responding, which leaves #49 unresolved Maybe we could talk about rewriting it to something like this: for (const { req, conn } of queueToProcess) {
if (req) {
// iterator should return response
const res = yield req;
// close connection if request body
// hasn't been consumed
writeResponse(res, req);
}
// check if connection can be reused
// get closed() should be added to `Conn`
if (!conn.closed) {
serveConn(env, conn);
}
} CC @ry @kevinkassimo |
Isn't code like this enough? After #188, for (const { req, conn } of queueToProcess) {
if (req) {
const res = createResponder(conn);
yield { req, res };
await copy({
write: async p => p.byteLength
}, req.body)
}
serveConn(env, conn);
} |
Follow up #22 #49.
This PR provides most basic implementation that handles unread request body without reading all data to memory. As discussed in #49 it follows Golang's implementation.