on master help sign in
show GET and POST params separately, no querystring
commitf02dcf91ab9edb4a9b59c516c12f9708759530ba authorGreg Weber <greg@gregweber.info> dateTue 19 Jul 2011, 13:51 (15 years ago) parenta5ce510
2 files changed+9−7
Network/Wai/Middleware/Debug.hs+7−5 runtests.hs+2−2
Network/Wai/Middleware/Debug.hs+7−5
@@ -25,24 +25,26 @@ debug = debugDest $ hPutStrLn stderr . T.unpack
2525debugDest :: (T.Text -> IO ()) -> Middleware
2626debugDest cb app req = do
2727 body <- consume
28− params <- if any (requestMethod req ==) ["GET", "HEAD"]
29− then return $ map emptyGetParam $ queryString req
28+ postParams <- if any (requestMethod req ==) ["GET", "HEAD"]
29+ then return []
3030 else do postParams <- liftIO $ allPostParams req body
3131 return $ collectPostParams postParams
32− let paramS = if null params then "" else "\n" ++ (show params)
32+ let getParams = map emptyGetParam $ queryString req
3333
3434 liftIO $ cb $ T.pack $ concat
3535 [ unpack $ requestMethod req
3636 , " "
3737 , unpack $ rawPathInfo req
38− , unpack $ rawQueryString req
3938 , "\n"
4039 , (++) "Accept: " $ maybe "" unpack $ lookup "Accept" $ requestHeaders req
41− , paramS
40+ , paramsToStr "GET " getParams
41+ , paramsToStr "POST " postParams
4242 ]
4343 -- we just consumed the body- fill the enumerator back up so it is available again
4444 liftIO $ run_ $ enumList 1 body $$ app req
4545 where
46+ paramsToStr prefix params = if null params then "" else "\n" ++ prefix ++ (show params)
47+
4648 allPostParams req body = run_ $ enumList 1 body $$ parseRequestBody lbsSink req
4749
4850 emptyGetParam :: (S.ByteString, Maybe S.ByteString) -> (S.ByteString, S.ByteString)
runtests.hs+2−2
@@ -406,8 +406,8 @@ caseDebugRequestBody = do
406406 }
407407 where
408408 params = [("foo", "bar"), ("baz", "bin")]
409− postOutput = T.pack $ "POST \nAccept: \n" ++ (show params)
410− getOutput qs = T.pack $ "GET /location" ++ S8.unpack qs ++ "\nAccept: \n" ++ (show params) -- \nAccept: \n" ++ (show params)
409+ postOutput = T.pack $ "POST \nAccept: \nPOST " ++ (show params)
410+ getOutput qs = T.pack $ "GET /location" ++ "\nAccept: \nGET " ++ (show params) -- \nAccept: \n" ++ (show params)
411411
412412 debugApp output = debugDest (\t -> liftIO $ assertEqual "debug" output t) $ \req -> do
413413 return $ responseLBS status200 [ ] ""