babashka / http-server

Serve static assets
MIT License
75 stars 8 forks source link

problems with using --headers #12

Closed lwiechec closed 7 months ago

lwiechec commented 7 months ago

I am having trouble adding extra headers (added by #8). For example. using http-server (as described here) - when I start it like this: http-server --dir "." --port 9998 --headers '{X-SomeHeader" "value"}', I do not see the header anywhere:

[luke:~] 7 $ curl -v http://localhost:9999
* Host localhost:9999 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:9999...
* Connected to localhost (::1) port 9999
> GET / HTTP/1.1
> Host: localhost:9999
> User-Agent: curl/8.5.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< content-length: 1488
< Server: http-kit
< Date: Thu, 8 Feb 2024 15:29:03 GMT
< 
<html><head>...

I am using babashka v1.3.186.

Maybe I am not using it correctly ?

borkdude commented 7 months ago

Does it make a difference when using a string key instead of a symbol key?

borkdude commented 7 months ago

Got it: the headers are currently only returned when a file is retrieved:

$ curl -I http://localhost:8090/README.md
HTTP/1.1 200 OK
X-Foo-Bar: bar
content-length: 2558
Server: http-kit
Date: Thu, 8 Feb 2024 15:40:24 GMT
lwiechec commented 7 months ago

thank you @borkdude for a quick check! I was too confused to try with getting a file...

borkdude commented 7 months ago

I changed the logic to always return the headers on every response.