On this page:
response/ basic
response/ full
response/ incremental
response/ c
make-xexpr-response
normalize-response
TEXT/ HTML-MIME-TYPE
Version: 4.1.5
2.4.3 Responses

 (require web-server/http/response-structs)

(struct response/basic (code message seconds mime headers))
  code : number?
  message : bytes?
  seconds : number?
  mime : bytes?
  headers : (listof header?)

A basic HTTP response containing no body. code is the response code, message the message, seconds the generation time, mime the MIME type of the file, and extras are the extra headers, in addition to those produced by the server.

Example:

  (make-response/basic
   301 #"Moved Permanently"
   (current-seconds) TEXT/HTML-MIME-TYPE
   (list (make-header #"Location"
                      #"http://www.plt-scheme.org/downloads")))

(struct (response/full response/basic) (body))
  body : (listof bytes?)

As with response/basic, except with body as the response body.

Example:

  (make-response/full
   301 #"Moved Permanently"
   (current-seconds) TEXT/HTML-MIME-TYPE
   (list (make-header #"Location"
                      #"http://www.plt-scheme.org/downloads"))
   (list #"<html><body><p>"
         #"Please go to <a href=\""
         #"http://www.plt-scheme.org/downloads"
         #"\">here</a> instead."
         #"</p></body></html>"))

(struct (response/incremental response/basic) (generator))
  generator : ((() () #:rest (listof bytes?) . ->* . any) . -> . any)

As with response/basic, except with generator as a function that is called to generate the response body, by being given an output-response function that outputs the content it is called with.

Here is a short example:

  (make-response/incremental
    200 #"OK" (current-seconds)
    #"application/octet-stream"
    (list (make-header #"Content-Disposition"
                       #"attachement; filename=\"file\""))
    (lambda (send/bytes)
      (send/bytes #"Some content")
      (send/bytes)
      (send/bytes #"Even" #"more" #"content!")
      (send/bytes #"Now we're done")))

response/c : contract?

Equivalent to (or/c response/basic? (cons/c bytes? (listof (or/c string? bytes?))) xexpr/c).

(make-xexpr-response xexpr    
  [#:code code    
  #:message message    
  #:seconds seconds    
  #:mime-type mime-type    
  #:headers headers])  response/full?
  xexpr : xexpr/c
  code : number? = 200
  message : bytes? = #"Okay"
  seconds : number? = (current-seconds)
  mime-type : bytes? = TEXT/HTML-MIME-TYPE
  headers : (listof header?) = empty

Equivalent to

  (make-response/full
     code message seconds mime-type headers
     (list (string->bytes/utf-8 (xexpr->string xexpr))))

(normalize-response close? response)
  (or/c response/full? response/incremental?)
  close? : boolean?
  response : response/c

Coerces response into a full response, filling in additional details where appropriate.

TEXT/HTML-MIME-TYPE : bytes?

Equivalent to #"text/html; charset=utf-8".

Warning: If you include a Content-Length header in a response that is inaccurate, there will be an error in transmission that the server will not catch.