-- | Serve an appropriate response for a folder request.
serveFolder :: StaticSettings -> Pieces -> W.Request -> Folder -> IO StaticResponse
serveFolder StaticSettings {..} pieces req folder@Folder {..} =
    case ssListing of
        Just _ | Just path <- addTrailingSlash req, ssAddTrailingSlash ->
            return $ RawRedirect path
        Just listing -> do
            -- directory listings turned on, display it
            builder <- listing pieces folder
            return $ WaiResponse $ W.responseBuilder H.status200
                [ ("Content-Type", "text/html; charset=utf-8")
                ] builder
        Nothing -> return $ WaiResponse $ W.responseLBS H.status403
            [ ("Content-Type", "text/plain")
            ] "Directory listings disabled"
serveFolder :: StaticSettings -> Pieces -> W.Request -> Folder -> IO StaticResponse
serveFolder StaticSettings {..} pieces req folder@Folder {..} =
    case ssListing of
        Just _ | Just path <- addTrailingSlash req, ssAddTrailingSlash ->
            return $ RawRedirect path
        Just listing -> do
            -- directory listings turned on, display it
            builder <- listing pieces folder
            return $ WaiResponse $ W.responseBuilder H.status200
                [ ("Content-Type", "text/html; charset=utf-8")
                ] builder
        Nothing -> return $ WaiResponse $ W.responseLBS H.status403
            [ ("Content-Type", "text/plain")
            ] "Directory listings disabled"
serveFolder StaticSettings {..} pieces req folder@Folder {..} =
    case ssListing of
        Just _ | Just path <- addTrailingSlash req, ssAddTrailingSlash ->
            return $ RawRedirect path
        Just listing -> do
            -- directory listings turned on, display it
            builder <- listing pieces folder
            return $ WaiResponse $ W.responseBuilder H.status200
                [ ("Content-Type", "text/html; charset=utf-8")
                ] builder
        Nothing -> return $ WaiResponse $ W.responseLBS H.status403
            [ ("Content-Type", "text/plain")
            ] "Directory listings disabled"