This module provides Middleware to rewrite URL paths. It also provides
functions that will convert a Request to a modified Request.
Both operations require a function that takes URL parameters and
headers, and returns new URL parameters. Parameters are pieces of URL
paths and query parameters.
Versions of this library in wai-extra ≤ 3.0.16.1 exported only
rewrite and rewritePure and both modified rawPathInfo of the
underlying requests. Such modification has been proscribed. The
semantics of these functions have not changed; instead the recommended
approach is to use rewriteWithQueries and rewritePureWithQueries.
The new functions are slightly different, as described in the section
on upgrading; code for previous library versions can be upgraded with
a single change, and as the type of the new function is different the
compiler will indicate where this change must be made.
A tuple of the path sections as [Text] and query parameters as
Query. This makes writing type signatures for the conversion
function far more pleasant.
Note that this uses Query not QueryText to more accurately
reflect the paramaters that can be supplied in URLs. It may be safe to
treat parameters as text; use the queryToQueryText and
queryTextToQuery functions to interconvert.
An example rewriting paths with queries
Let’s say we want to replace a website written in PHP with one written
using WAI. We’ll use the
http-reverse-proxy
package to serve the old
site from the new site, but there’s a problem. The old site uses pages like
index.php?page=page
whereas the new site would look like
index/page
In doing this, we want to separate the migration code from our new
website. So we’d like to handle links internally using the path
formulation, but externally have the old links still work.
Therefore, we will use middleware (rewritePureWithQueries) from this
module to rewrite incoming requests from the query formulation to the
paths formulation.
On the other side, we will use rewriteRequestPure to rewrite outgoing
requests to the original website from the reverse proxy code (using the
Network.HTTP.ReverseProxy.WPRModifiedRequest or
Network.HTTP.ReverseProxy.WPRModifiedRequestSecure constructors. Note,
these links will only work if the haddock documentation for
http-reverse-proxy
is installed).
This modifies the rawPathInfo field of a Request. This is not recommended behaviour; it is however how this function has worked in the past. Use rewriteWithQueries instead
Rewrite based on your own conversion function for paths only, to be
supplied by users of this library (with the conversion operating in IO).
This modifies the rawPathInfo field of a Request. This is not recommended behaviour; it is however how this function has worked in the past. Use rewritePureWithQueries instead
Rewrite based on pure conversion function for paths only, to be
supplied by users of this library.