Skip to content

Commit

Permalink
Fix gxhttpd bug: No content length when chunking (#1292)
Browse files Browse the repository at this point in the history
That was against the standard.
  • Loading branch information
drewc authored Jan 15, 2025
1 parent a3161a5 commit 1de5c05
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/tools/gxhttpd.ss
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
(mux (make-mux cfg))
(request-logger (get-request-logger cfg))
(addresses (config-get! cfg listen:))
(max-token-length (: (config-get cfg max-token-length: 1024) :fixnum))
(max-token-length (: (config-get cfg max-token-length: 1024) :fixnum))
(run-httpd
(lambda ()
(set-httpd-max-token-length! max-token-length)
Expand Down Expand Up @@ -478,11 +478,11 @@
=> :procedure
(let* ((content-type (path-extension->mime-type-name path))
(headers
[(if content-type
[["Content-Length" :: (number->string (file-info-size info))]
(if content-type
["Content-Type" :: content-type]
["Content-Type" :: "application/octet-stream"])
["Last-Modified" :: (number->string (exact (floor (time->seconds (file-info-last-modification-time info)))))]
["Content-Length" :: (number->string (file-info-size info))]]))
["Last-Modified" :: (number->string (exact (floor (time->seconds (file-info-last-modification-time info)))))]]))

(if (fx<= (file-info-size info) max-file-cache-size)
;; cache the content
Expand All @@ -501,12 +501,16 @@
(using (req :- http-request)
(case req.method
((GET)
(http-response-file res headers path))
;; RFC 9112 states that "a sender (server) MUST NOT send
;; a Content-Length header field in any message that
;; contains a Transfer-Encoding header field.".
(http-response-file res (cdr headers) path))
((HEAD)
(http-response-write res 200 headers #f))
(else
(http-response-write-condition res Forbidden))))))))


(def (find-handler tab server-path)
(let loop ((path server-path))
(cond
Expand Down

0 comments on commit 1de5c05

Please sign in to comment.