-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
bug report! If koa and http2server are used together, the response with method "head" request will never end! #1547
Comments
My solution is to modify it as follows and everything works fine! import http2 from "http2";
import Koa from "koa";
import fs from "fs";
import { fileURLToPath } from "url";
import { join, dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const app = new Koa();
const selfSignedKey = join(__dirname, "./certs/self-signed.key.pem");
const selfSignedCert = join(__dirname, "./certs/self-signed.cert.pem");
//
app.use(async (ctx, next) => {
await next();
if (ctx.method === "HEAD") {
ctx.res.end();
}
return;
});
//
app.use((ctx) => {
ctx.body = "Hello Koa";
});
const config = {
sslKey: fs.readFileSync(selfSignedKey).toString(),
sslCert: fs.readFileSync(selfSignedCert).toString(),
};
const serverHandler = app.callback();
const httpsopt = { cert: config.sslCert, key: config.sslKey };
const server = http2.createSecureServer(httpsopt, serverHandler);
server.on("listening", () => {
console.log(`Server listening on ` + JSON.stringify(server.address()));
});
server.listen(3000); |
Line 535 in 698ce0a
I found the problem, if it is the'http2' server and the method is 'head', the "socket.writable" is "false". If it is the'http1' server, the "socket.writable" is "true". |
The same error also occurs when the client closes the connection before the server had a chance to respond, causing the socket to no longer be writable. This can cause pending connections, because All other Instead of checking for ctx.method === "HEAD" as was done in #1548 I'd suggest replacing this line with the following: if (!ctx.writable) {
return res.end();
} Would you like a separate Pull request for this @jonathanong ? |
Why has this problem not been solved after two years? |
bug report! If koa and http2server are used together, the response with method "head" request will never end!
Initiate a "head" request in the browser.
the response with method "head" request will never end!
The text was updated successfully, but these errors were encountered: