2.2 Mapping URLs to Paths

► |  | 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 | Basic Logging
2.11 | Password Protection
2.12 | Virtual Hosts
2.13 | Serving Files
2.14 | Serving Servlets
2.15 | Statistics
2.16 | Limiting Requests
2.17 | Wrapping Requests & Responses

On this page:

url->path/ c
make-url->path
make-url->valid-path
filter-url->path

Racket
top contents ← prev up next →

### 2.2 Mapping URLs to Paths🔗ℹ

(require web-server/dispatchers/filesystem-map)
| package: web-server-lib

This module provides a means of mapping URLs to paths on the filesystem.

> value url->path/c : contract?

This contract is equivalent to (->* (url?) (path? (listof path-piece?))). The returned path? is the path on disk. The list is the list of path elements that correspond to the path of the URL.

> procedure (make-url->path base) → url->path/c
> base : path-string?

The url->path/c returned by this procedure considers the root URL to be base. It ensures that ".."s in the URL do not escape the base and removes them silently otherwise.

> procedure (make-url->valid-path url->path) → url->path/c
> url->path : url->path/c

Runs the underlying url->path, but only returns if the path refers to a file that actually exists. If it is does not, then the suffix elements of the URL are removed until a file is found. If this never occurs, then an error is thrown.
This is primarily useful for dispatchers that allow path information after the name of a service to be used for data, but where the service is represented by a file. The most prominent example is obviously servlets.

> procedure (filter-url->path regex url->path) → url->path/c
> regex : regexp?
> url->path : url->path/c

Runs the underlying url->path but will only return if the path, when considered as a string, matches the regex. This is useful to disallow strange files, like GIFs, from being considered servlets when using the servlet dispatchers. It will return a exn:fail:filesystem:exists? exception if the path does not match.
top contents ← prev up next →