diff --git a/collects/web-server/http/response-structs.rkt b/collects/web-server/http/response-structs.rkt index 202288a7c5..c6fb464fc4 100644 --- a/collects/web-server/http/response-structs.rkt +++ b/collects/web-server/http/response-structs.rkt @@ -19,7 +19,7 @@ (define (response/full->size resp) (apply + (map bytes-length (response/full-body resp)))) -(define (normalize-response close? resp) +(define (normalize-response resp [close? #f]) (cond [(response/full? resp) (make-response/full @@ -43,14 +43,14 @@ (response/incremental-generator resp)))] [(response/basic? resp) (normalize-response - close? (make-response/full (response/basic-code resp) (response/basic-message resp) (response/basic-seconds resp) (response/basic-mime resp) (response/basic-headers resp) - empty))] + empty) + close?)] [(and (list? resp) (not (empty? resp)) (bytes? (first resp)) @@ -58,18 +58,18 @@ (bytes? i))) (rest resp))) (normalize-response - close? (make-response/full 200 #"Okay" (current-seconds) (car resp) empty (map (lambda (bs) (if (string? bs) (string->bytes/utf-8 bs) bs)) - (rest resp))))] + (rest resp))) + close?)] [else (normalize-response - close? - (make-xexpr-response resp))])) + (make-xexpr-response resp) + close?)])) (define (make-xexpr-response xexpr @@ -108,5 +108,5 @@ ((pretty-xexpr/c) (#:code number? #:message bytes? #:seconds number? #:mime-type bytes? #:headers (listof header?)) . ->* . response/full?)] - [normalize-response (boolean? response/c . -> . (or/c response/full? response/incremental?))] + [normalize-response ((response/c) (boolean?) . ->* . (or/c response/full? response/incremental?))] [TEXT/HTML-MIME-TYPE bytes?]) diff --git a/collects/web-server/http/response.rkt b/collects/web-server/http/response.rkt index e342355bd8..a474bbbf8d 100644 --- a/collects/web-server/http/response.rkt +++ b/collects/web-server/http/response.rkt @@ -59,7 +59,7 @@ (output-response/method conn resp #"GET")) (define (output-response/method conn resp meth) - (define bresp (normalize-response (connection-close? conn) resp)) + (define bresp (normalize-response resp (connection-close? conn))) (output-headers+response/basic conn bresp) (unless (bytes-ci=? meth #"HEAD") (output-response/basic conn bresp))) diff --git a/collects/web-server/scribblings/http.scrbl b/collects/web-server/scribblings/http.scrbl index 605beb40da..2de2af8a3a 100644 --- a/collects/web-server/scribblings/http.scrbl +++ b/collects/web-server/scribblings/http.scrbl @@ -246,9 +246,12 @@ Here is an example typical of what you will find in many applications: (list (string->bytes/utf-8 (xexpr->string xexpr)))) ]} -@defproc[(normalize-response [close? boolean?] [response response/c]) +@defproc[(normalize-response [response response/c] [close? boolean? #f]) (or/c response/full? response/incremental?)]{ Coerces @racket[response] into a full response, filling in additional details where appropriate. + + @racket[close?] represents whether the connection will be closed after the response is sent (i.e. if HTTP 1.0 is being used.) The accuracy of this only matters if +@racket[response] is a @racket[response/incremental?]. } @defthing[TEXT/HTML-MIME-TYPE bytes?]{Equivalent to @racket[#"text/html; charset=utf-8"].}