on master help sign in
Fix bug in JSONP
5d66286Michael Snoyman
Network/Wai/Middleware/Jsonp.hs+4−2
@@ -24,6 +24,7 @@ import Blaze.ByteString.Builder.Char8 (fromChar)
24import Data.Monoid (mappend)
24import Data.Monoid (mappend)
25import Control.Monad (join)
25import Control.Monad (join)
26import Data.Maybe (fromMaybe)
26import Data.Maybe (fromMaybe)
27+import qualified Data.ByteString as S
27
28
28-- | Wrap json responses in a jsonp callback.
29-- | Wrap json responses in a jsonp callback.
29--
30--
@@ -68,8 +69,9 @@ jsonp app env = do
68 Just _ -> addCallback c $ responseEnumerator r
69 Just _ -> addCallback c $ responseEnumerator r
69 Nothing -> return r
70 Nothing -> return r
70 checkJSON hs =
71 checkJSON hs =
71− case fmap B8.unpack $ lookup "Content-Type" hs of
72+ case lookup "Content-Type" hs of
73+ Just x
72− Just "application/json" -> Just $ fixHeaders hs
74+ | B8.pack "application/json" `S.isPrefixOf` x -> Just $ fixHeaders hs
73 _ -> Nothing
75 _ -> Nothing
74 fixHeaders = changeVal "Content-Type" "text/javascript"
76 fixHeaders = changeVal "Content-Type" "text/javascript"
75 addCallback :: B8.ByteString -> (forall a. ResponseEnumerator a)
77 addCallback :: B8.ByteString -> (forall a. ResponseEnumerator a)
wai-extra.cabal+1−1
@@ -1,5 +1,5 @@
1Name: wai-extra
1Name: wai-extra
2−Version: 0.4.0
2+Version: 0.4.0.1
3Synopsis: Provides some basic WAI handlers and middleware.
3Synopsis: Provides some basic WAI handlers and middleware.
4Description: The goal here is to provide common features without many dependencies.
4Description: The goal here is to provide common features without many dependencies.
5License: BSD3
5License: BSD3