scotty-path-normalizer: Redirect to a normalized path

[ library, mit, web ] [ Propose Tags ]

Interprets dots and slashes and issues a redirect to a normalized path if the request target is not already in normal form.

[Skip to Readme]
Versions [RSS] [faq]
Dependencies base (>=4.7 && <5), bytestring, scotty, text, wai [details]
License MIT
Copyright 2018 Typeclass Consulting, LLC
Author Chris Martin
Maintainer Chris Martin, Julie Moronuki
Category Web
Home page
Bug tracker
Source repo head: git clone
Uploaded by chris_martin at 2018-10-22T23:40:31Z
Distributions NixOS:
Downloads 534 total (10 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2018-10-22 [all 1 reports]


[Index] [Quick Jump]


Maintainer's Corner

For package maintainers and hackage trustees


Readme for scotty-path-normalizer-

[back to package description]

Scotty path normalizer

This library provides a Scotty action that normalizes the HTTP request target as if it were a Unix file path. When the path normalization action detects a path that can be simplified in one of the following ways, it issues a redirect to a more canonical path.

  1. Remove trailing slashes: becomes
  2. Remove double slashes: becomes
  3. Remove . segments, because . represents "the current directory": becomes
  4. Remove segments of the form xyz/.., because .. represents "the parent directory": becomes

The typical way to apply this to your Scotty server is to put addPathNormalizer at the top of your ScottyM app definition.

import qualified Web.Scotty as Scotty
import Web.Scotty.PathNormalizer (addPathNormalizer)

main :: IO ()
main =
    Scotty.scotty 3000 $

        Scotty.get (Scotty.capture "/:word") $
            beam <- Scotty.param (Data.Text.Lazy.pack "word")
            Scotty.html $ fold
                [ Data.Text.Lazy.pack "<h1>Scotty, "
                , beam
                , Data.Text.Lazy.pack " me up!</h1>"