mirror of
https://github.com/typeable/wai.git
synced 2025-01-06 05:25:53 +03:00
show GET params when GET, else show body params
always show query string
This commit is contained in:
parent
a9df06e5eb
commit
a5ce5107f9
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
*.swp
|
||||
dist
|
||||
cabal-dev
|
||||
|
@ -26,29 +26,29 @@ debugDest :: (T.Text -> IO ()) -> Middleware
|
||||
debugDest cb app req = do
|
||||
body <- consume
|
||||
params <- if any (requestMethod req ==) ["GET", "HEAD"]
|
||||
then return []
|
||||
then return $ map emptyGetParam $ queryString req
|
||||
else do postParams <- liftIO $ allPostParams req body
|
||||
return $ collectPostParams postParams
|
||||
let allParams = params ++ (map emptyGetParam $ queryString req)
|
||||
let paramS = if null params then "" else "\n" ++ (show params)
|
||||
|
||||
liftIO $ cb $ T.pack $ concat
|
||||
[ unpack $ requestMethod req
|
||||
, " "
|
||||
, unpack $ rawPathInfo req
|
||||
, unpack $ rawQueryString req
|
||||
, "\n"
|
||||
, (++) "Accept: " $ maybe "" unpack $ lookup "Accept" $ requestHeaders req
|
||||
, "\n"
|
||||
, show allParams
|
||||
, paramS
|
||||
]
|
||||
-- we just consumed the body- fill the enumerator back up so it is available again
|
||||
liftIO $ run_ $ enumList 1 body $$ app req
|
||||
where
|
||||
allPostParams req body = run_ $ enumList 1 body $$ parseRequestBody lbsSink req
|
||||
|
||||
collectPostParams :: ([Param], [File L.ByteString]) -> [Param]
|
||||
collectPostParams (postParams, files) = postParams ++
|
||||
(map (\(k,v) -> (k, S.append "FILE: " (fileName v))) files)
|
||||
|
||||
emptyGetParam :: (S.ByteString, Maybe S.ByteString) -> (S.ByteString, S.ByteString)
|
||||
emptyGetParam (k, Just v) = (k,v)
|
||||
emptyGetParam (k, Nothing) = (k,"")
|
||||
|
||||
collectPostParams :: ([Param], [File L.ByteString]) -> [Param]
|
||||
collectPostParams (postParams, files) = postParams ++
|
||||
(map (\(k,v) -> (k, S.append "FILE: " (fileName v))) files)
|
||||
|
24
runtests.hs
24
runtests.hs
@ -389,15 +389,27 @@ caseDalvikMultipart = do
|
||||
length files @?= 1
|
||||
|
||||
caseDebugRequestBody :: Assertion
|
||||
caseDebugRequestBody = flip runSession debugApp $ do
|
||||
let req = toRequest "application/x-www-form-urlencoded" "foo=bar&baz=bin"
|
||||
res <- srequest req
|
||||
assertStatus 200 res
|
||||
caseDebugRequestBody = do
|
||||
flip runSession (debugApp postOutput) $ do
|
||||
let req = toRequest "application/x-www-form-urlencoded" "foo=bar&baz=bin"
|
||||
res <- srequest req
|
||||
assertStatus 200 res
|
||||
|
||||
let qs = "?foo=bar&baz=bin"
|
||||
flip runSession (debugApp $ getOutput qs) $ do
|
||||
assertStatus 200 =<< request Request
|
||||
{ requestMethod = "GET"
|
||||
, queryString = map (\(k,v) -> (k, Just v)) params
|
||||
, rawQueryString = qs
|
||||
, requestHeaders = []
|
||||
, rawPathInfo = "/location"
|
||||
}
|
||||
where
|
||||
params = [("foo", "bar"), ("baz", "bin")]
|
||||
debugOutput = T.pack $ "POST \nAccept: \n" ++ (show params)
|
||||
postOutput = T.pack $ "POST \nAccept: \n" ++ (show params)
|
||||
getOutput qs = T.pack $ "GET /location" ++ S8.unpack qs ++ "\nAccept: \n" ++ (show params) -- \nAccept: \n" ++ (show params)
|
||||
|
||||
debugApp = debugDest (\t -> liftIO $ assertEqual "debug" debugOutput t) $ \req -> do
|
||||
debugApp output = debugDest (\t -> liftIO $ assertEqual "debug" output t) $ \req -> do
|
||||
return $ responseLBS status200 [ ] ""
|
||||
{-debugApp = debug $ \req -> do-}
|
||||
{-return $ responseLBS status200 [ ] ""-}
|
||||
|
Loading…
Reference in New Issue
Block a user