Suppose I have a serving of static files, but they are without extension. I want to set header "Content-Type: image/png" for all of them which are serving from "some/" (1st rule). How to do it in this code?
import Network.Wai.Middleware.Static
import Web.Scotty
routes :: Scotty M ()
routes = do
...
middleware $ staticPolicy $
contains "some/" >-> (addBase "/something/files/")
<|>
addBase "/elsewhere/"
I tried this:
setContentType :: Middleware
setContentType = modifyResponse $ mapResponseHeaders
(("Content-Type", "image/png"):)
reqInfixedWith :: Text -> Request -> Bool
reqInfixedWith str req =
isInfixOf str $ convertString $ rawQueryString req
...
-- in routes
middleware $ ifRequest (reqInfixedWith "some/") setContentType
and checked with Debug.Trace
request's path, query string - all are empty, while actual request is "...:8080/some/somefile".
What is the correct way to do it?