► |  | Web Server: PLT HTTP Server

1 | Running the Web Server
2 | Writing Servlets
3 | Extending the Web Server
4 | Troubleshooting and Tips
5 | Acknowledgements
| Index

► | 2 | Writing Servlets

2.1 | Defining a Servlet
2.2 | APIs
2.3 | Common Contracts
2.4 | HTTP
2.5 | Web Interaction
2.6 | Stateless Web Interaction
2.7 | Web Cells
2.8 | File Boxes
2.9 | Stateless Web Parameters
2.10 | Formlets
2.11 | Templates
2.12 | Continuation Managers

▼ | 2.4 | HTTP

2.4.1 | Requests
2.4.2 | Bindings
2.4.3 | Responses
2.4.4 | Redirect
2.4.5 | Basic Authentication

On this page:

response/ basic
response/ full
response/ incremental
response?
TEXT/ HTML-MIME-TYPE

Version: 4.1.4
top← prev up next →

##### 2.4.3`` Responses

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

(struct response/basic (code message seconds mime headers))
code : number?
message : string?
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 (or/c string? 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 : ((() (listof (or/c bytes? string?)) . ->* . 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? v) → boolean?
v : any/c

Checks if v is a valid response. A response is either:

- A response/basic structure.

- A value matching the contract (cons/c (or/c bytes? string?) (listof (or/c bytes? string?))).

- A value matching xexpr?.

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.

top← prev up next →