HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulewai-extra-3.1.16Haskell2010

Network.Wai.Middleware.RequestSizeLimit

The functions in this module allow you to limit the total size of incoming request bodies.

Limiting incoming request body size helps protect your server against denial-of-service (DOS) attacks, in which an attacker sends huge bodies to your server.

  • 1 type
  • 4 values
  • Packagewai-extra-3.1.16
  • Exports5
  • LanguageHaskell2010
  • LicenceMIT
  • SourceRequestSizeLimit.hs

Middleware

1 declaration

Constructing RequestSizeLimitSettings

1 declaration

RequestSizeLimitSettings and accessors

3 declarations

Settings to configure requestSizeLimitMiddleware.

This type (but not the constructor, or record fields) is exported from Network.Wai.Middleware.RequestSizeLimit. Since the constructor isn't exported, create a default value with defaultRequestSizeLimitSettings first, then set the values using setMaxLengthForRequest and setOnLengthExceeded (See the examples below).

If you need to access the constructor directly, it's exported from Network.Wai.Middleware.RequestSizeLimit.Internal.

Examples
Conditionally setting the limit based on the request
{-# LANGUAGE OverloadedStrings #-}
import Network.Wai
import Network.Wai.Middleware.RequestSizeLimit

let megabyte = 1024 * 1024
let sizeForReq req = if pathInfo req == ["upload", "image"] then pure $ Just $ megabyte * 20 else pure $ Just $ megabyte * 2
let finalSettings = setMaxLengthForRequest sizeForReq defaultRequestSizeLimitSettings
JSON response
{-# LANGUAGE OverloadedStrings #-}
import Network.Wai
import Network.Wai.Middleware.RequestSizeLimit
import Network.HTTP.Types.Status (requestEntityTooLarge413)
import Data.Aeson
import Data.Text (Text)

let jsonResponse = \_maxLen _app _req sendResponse -> sendResponse $ responseLBS requestEntityTooLarge413 [("Content-Type", "application/json")] (encode $ object ["error" .= ("request size too large" :: Text)])
let finalSettings = setOnLengthExceeded jsonResponse defaultRequestSizeLimitSettings