@@ -126,12 +126,12 @@ import Control.Applicative
126126-- > rewritePathFromPhp :: Middleware
127127-- > rewritePathFromPhp = rewritePureWithQueries pathFromPhp
128128-- >
129−-- > pathFromPhp :: PathsAndQueries -> RequestHeaders -> PathsAndQueries
129+-- > pathFromPhp :: PathsAndQueries -> H.RequestHeaders -> PathsAndQueries
130130-- > pathFromPhp (pieces, queries) _ = piecesConvert pieces queries
131131-- > where
132−-- > piecesConvert :: [Text] -> QueryText -> PathsAndQueries
132+-- > piecesConvert :: [Text] -> H.Query -> PathsAndQueries
133133-- > piecesConvert ["index.php"] qs@(join . lookup "page" -> Just page) =
134−-- > ( ["index", page]
134+-- > ( ["index", TE.decodeUtf8With TE.lenientDecode page]
135135-- > , delete ("page", pure page) qs
136136-- > )
137137-- > piecesConvert ps qs = (ps, qs)
@@ -147,11 +147,11 @@ import Control.Applicative
147147-- > rewritePhpFromPath :: Request -> Request
148148-- > rewritePhpFromPath = rewriteRequestPure phpFromPath
149149-- >
150−-- > phpFromPath :: PathsAndQueries -> RequestHeaders -> PathsAndQueries
150+-- > phpFromPath :: PathsAndQueries -> H.RequestHeaders -> PathsAndQueries
151151-- > phpFromPath (pieces, queries) _ = piecesConvert pieces queries
152152-- > where
153−-- > piecesConvert :: [Text] -> QueryText -> PathsAndQueries
154−-- > piecesConvert ("index":page:[]) qs = ( ["index.php"], ("page", pure page) : qs )
153+-- > piecesConvert :: [Text] -> H.Query -> PathsAndQueries
154+-- > piecesConvert ["index", page] qs = ( ["index.php"], ("page", pure . TE.encodeUtf8 $ page) : qs )
155155-- > piecesConvert ps qs = (ps, qs)
156156--
157157-- For the whole example, see
@@ -205,9 +205,14 @@ import Control.Applicative
205205--------------------------------------------------
206206
207207-- | A tuple of the path sections as ['Text'] and query parameters as
208−-- 'H.QueryText'. This makes writing type signatures for the conversion
208+-- 'H.Query'. This makes writing type signatures for the conversion
209209-- function far more pleasant.
210−type PathsAndQueries = ([Text], H.QueryText)
210+--
211+-- Note that this uses 'H.Query' not 'H.QueryText' to more accurately
212+-- reflect the paramaters that can be supplied in URLs. It may be safe to
213+-- treat parameters as text; use the 'H.queryToQueryText' and
214+-- 'H.queryTextToQuery' functions to interconvert.
215+type PathsAndQueries = ([Text], H.Query)
211216
212217--------------------------------------------------
213218-- * Rewriting 'Middleware'
@@ -287,8 +292,8 @@ rewriteRequestM :: (Applicative m, Monad m)
287292 => (PathsAndQueries -> H.RequestHeaders -> m PathsAndQueries)
288293 -> Request -> m Request
289294rewriteRequestM convert req = do
290− (pInfo, qText) <- curry convert (pathInfo req) (H.queryToQueryText . queryString $ req) (requestHeaders req)
291− pure req {pathInfo = pInfo, queryString = H.queryTextToQuery qText}
295+ (pInfo, qByteStrings) <- curry convert (pathInfo req) (queryString req) (requestHeaders req)
296+ pure req {pathInfo = pInfo, queryString = qByteStrings}
292297
293298-- | This helper function preserves the semantics of wai-extra ≤ 3.0, in
294299-- which the rewrite functions modify the 'rawPathInfo' parameter. Note