packages feed

hack-middleware-jsonp 0.0.0 → 0.0.1

raw patch · 2 files changed

+20/−15 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

Hack/Middleware/Jsonp.hs view
@@ -29,7 +29,7 @@ -- callback function. jsonp :: Middleware jsonp app env = do-    let accept = fromMaybe "" $ lookup "HTTP_ACCEPT" $ http env+    let accept = fromMaybe "" $ lookup "Accept" $ http env     let gets = decodeUrlPairs $ queryString env     let callback :: Maybe String         callback =@@ -40,24 +40,29 @@             case callback of                 Nothing -> env                 Just _ -> env-                        { http = changeVal "HTTP_ACCEPT"+                        { http = changeVal "Accept"                                            "application/json"                                            $ http env                         }     res <- app env'+    let ctype = fromMaybe "" $ lookup "Content-Type" $ headers res+    putStrLn $ "callback: " ++ show callback ++ ", ctype: " ++ show ctype ++ ", accept: " ++ accept     case callback of-            Nothing -> return res-            Just c -> return $ res-                    { headers = changeVal "Content-type"-                                          "text/javascript"-                                          $ headers res-                    , body = BS.concat-                                [ toLazyByteString c-                                , toLazyByteString "("-                                , body res-                                , toLazyByteString ")"-                                ]-                    }+        Nothing -> return res+        Just c ->+          case ctype of+            "application/json" -> return $ res+                { headers = changeVal "Content-Type"+                                      "text/javascript"+                                      $ headers res+                , body = BS.concat+                            [ toLazyByteString c+                            , toLazyByteString "("+                            , body res+                            , toLazyByteString ")"+                            ]+                }+            _ -> return res  changeVal :: String -> String -> [(String, String)] -> [(String, String)] changeVal key val old = (key, val) : filter (\(k, _) -> k /= key) old
hack-middleware-jsonp.cabal view
@@ -1,5 +1,5 @@ name:            hack-middleware-jsonp-version:         0.0.0+version:         0.0.1 license:         BSD3 license-file:    LICENSE author:          Michael Snoyman <michael@snoyman.com>