Network.Wai pathInfo Request is empty

Hello, I was doing a tutorial about a generalized authentication (LINK), I have found one strange thing.

The pathInfo req command returns an empty list. Even if I go to the paths such as “a/b/c”, the pathInfo is still an empty list. Why? Probably the AuthHandler has already removed the Path from the request, and therefore the pathInfo is always empty here?

import Network.Wai (Request, pathInfo)

describeRequest :: Request -> IO ()
describeRequest req = do
  let urlParts = pathInfo req
  print urlParts

I call this describeRequest function inside this authHandler (shortened for clarity):

authHandler :: PostgresConnection -> AuthHandler Request User
authHandler conn = mkAuthHandler handler
  where
    handler req = do
      ...
      liftIO $ describeRequest req
      ...

Update: rawPathInfo req works and prints correct urls, e.g. “/a/b”. But pathInfo req always returns empty list. Issue closed. I think that at the Servant authentication stage, the path has already been processed by the server, and therefore this remaining path is empty.

1 Like

What if you put the AuthProtect before any "path" :> you can go to? Will it show the paths pieces that are behind it?

So e.g. "first" :> AuthProtect MyType :> "second" :> Get '[PlainText] Text and make a request to /first/second? Would that print ["second"]?

1 Like