abc
abc copied to clipboard
Hello World example keeps connection left intact
Just tested the super-simple Hello World example from Readme.md and the following command:
curl -H "Connection:close" localhost:8080/hello -i -vvv1
returns:
* Connection #0 to host ... left intact
It keeps the connection open even though the Connection:close is sent. I should correctly generate:
* Closing connection 0
but it does not. How can it be achieved?
Version: Deno 1.16.2 ABC version: https://deno.land/x/[email protected]/mod.ts
Looks like this is an issue with the std/http module
In nodejs, res.end()
will get some useful information from req.headers
and merge it into res.headers
, while in deno new Response()
will create a new headers.
In Abc, you can use middleware
:
app.pre(h => {
return c => {
const connection = c.request.headers.get("Connection");
if (connection) {
c.response.headers.set("Connection", connection);
}
return h(c);
}
})
app
.get("/hello", (c) => {
return "Hello, Abc!";
})
.start({ port: 8080 });
Or meet more custom functions through CustomContext
Unfortunately, even this super-simple example does not close the connection:
const app = new Application()
app.pre((h) => {
return (c) => {
c.response.headers.set("Connection", "close")
return h(c)
}
})
app.get("/hello", (c) => {
return "hello"
}).start({ port })
This is my output, make sure you have local proxy turned off.
* Trying ::1:8080...
* connect to ::1 port 8080 failed: Connection refused
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /hello HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.77.0
> Accept: */*
> Connection:close
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< content-length: 11
content-length: 11
< connection: close
connection: close
< content-type: text/plain; charset=UTF-8
content-type: text/plain; charset=UTF-8
<
* Closing connection 0
Hello, Abc!
I do think there may be an issue in place here because if I switch this hello world for, for example, a native Deno router, the connection is closed properly. Switching back to the hello world keeps the connection open.
This was revealed via the telnet command only. Curl appeared ok.