vercel / serve-handler

The foundation of `serve`

Home Page:https://npmjs.com/serve-handler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Content-Length header missing on GET but present on HEAD request

call-a3 opened this issue · comments

When trying to request a file (both when using fetch from the browser or via httpie), the Content-Length header is present when performing a HEAD request, but absent when performing a GET request for the same file.

$ npx serve . & # running serve in the folder that contains a file named sizes.csv
$ http get http://localhost:3000/sizes.csv
HTTP/1.1 200 OK
Accept-Ranges: bytes
Connection: keep-alive
Content-Disposition: inline; filename="sizes.csv"
Content-Encoding: gzip
Content-Type: text/csv; charset=utf-8
Date: Tue, 01 Feb 2022 16:41:31 GMT
ETag: "fe6386cd1487ccd8226d4750f395b4bac29a9465"
Keep-Alive: timeout=5
Transfer-Encoding: chunked
Vary: Accept-Encoding

^C # aborted because I didn't want to download the actual file in this test
$ http head http://localhost:3000/sizes.csv
HTTP/1.1 200 OK
Accept-Ranges: bytes
Connection: keep-alive
Content-Disposition: inline; filename="sizes.csv"
Content-Length: 920509727
Content-Type: text/csv; charset=utf-8
Date: Tue, 01 Feb 2022 16:41:38 GMT
ETag: "fe6386cd1487ccd8226d4750f395b4bac29a9465"
Keep-Alive: timeout=5
Vary: Accept-Encoding

get response Transfer-Encoding: chunked

Data is sent in a series of chunks. The Content-Length header is omitted in this case, and at the beginning of each chunk you need to add the length of the current chunk in hexadecimal format...