► |  | Web Server: HTTP Server

1 | Dispatching Server
2 | Dispatchers
3 | Launching Servers
4 | Web Servers
5 | Internal APIs
6 | Troubleshooting and Tips
| Index

▼ | 2 | Dispatchers

2.1 | General
2.2 | Mapping URLs to Paths
2.3 | Sequencing
2.4 | Timeouts
2.5 | Lifting Procedures
2.6 | Filtering Requests by URL
2.7 | Filtering Requests by Method
2.8 | Procedure Invocation upon Request
2.9 | Logging
2.10 | Password Protection
2.11 | Virtual Hosts
2.12 | Serving Files
2.13 | Serving Servlets
2.14 | Statistics
2.15 | Limiting Requests

On this page:

make

top ← prev up next →

#### 2.12`` Serving Files

(require web-server/dispatchers/dispatch-files)
| package: web-server-lib

The web-server/dispatchers/dispatch-files module allows files to be served. It defines a dispatcher construction procedure.

> > procedure

> > (make |  | #:url->path url->path |  |  |  |
> > | [ | #:path->mime-type path->mime-type |  |  |  |
> > |  | #:indices indices]) |  | → |  | dispatcher/c

> url->path : url->path/c

> | path->mime-type |  | : |  | (path? . -> . (or/c false/c bytes)?)
> |  |  | = |  | (lambda (path) #f)

> indices : (listof string?) = (list "index.html" "index.htm")

Uses url->path to extract a path from the URL in the request object. If this path does not exist, then the dispatcher does not apply and next-dispatcher is invoked. If the path is a directory, then the indices are checked in order for an index file to serve. In that case, or in the case of a path that is a file already, path->mime-type is consulted for the MIME Type of the path. The file is then streamed out the connection object.

This dispatcher supports HTTP Range GET requests and HEAD requests. If the request’s method is neither HEAD nor GET, next-dispatcher will be called.

If the path works out to something on disk (either as a file, or, if the path refers to directory, one of the specified indices files in that directory), it needs to be readable by the process that is running the web server. Existing but unreadable files are handled as non-existing files.

Changed in version 1.7 of package web-server-lib: Support for non-{GET,HEAD} requests.
Changed in version 1.7: Treat unreadable files as non-existing files.

top ← prev up next →