on develop help sign in
List requested headers with Set rather than List; cleanup
1292164Greg Hale
src/Reflex/Dom/Xhr.hs+6−6
@@ -5,7 +5,6 @@
5{-# LANGUAGE MultiParamTypeClasses #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
6{-# LANGUAGE OverloadedStrings #-}
6{-# LANGUAGE OverloadedStrings #-}
7{-# LANGUAGE TemplateHaskell #-}
7{-# LANGUAGE TemplateHaskell #-}
8−{-# LANGUAGE TupleSections #-}
9module Reflex.Dom.Xhr
8module Reflex.Dom.Xhr
10 ( XMLHttpRequest
9 ( XMLHttpRequest
11 , XhrRequest (..)
10 , XhrRequest (..)
@@ -78,6 +77,7 @@ import Data.Default
78import Data.Map (Map)
77import Data.Map (Map)
79import qualified Data.Map as Map
78import qualified Data.Map as Map
80import Data.Maybe
79import Data.Maybe
80+import qualified Data.Set as Set
81import Data.Text (Text)
81import Data.Text (Text)
82import qualified Data.Text as T
82import qualified Data.Text as T
83import Data.List
83import Data.List
@@ -115,12 +115,12 @@ data XhrResponse
115 deriving (Typeable)
115 deriving (Typeable)
116
116
117data XhrResponseHeaders =
117data XhrResponseHeaders =
118− OnlyHeaders [Text] -- ^ Parse a subset of headers from the XHR Response
118+ OnlyHeaders (Set.Set Text) -- ^ Parse a subset of headers from the XHR Response
119 | AllHeaders -- ^ Parse all headers from the XHR Response
119 | AllHeaders -- ^ Parse all headers from the XHR Response
120 deriving (Show, Read, Eq, Ord, Typeable)
120 deriving (Show, Read, Eq, Ord, Typeable)
121
121
122instance Default XhrResponseHeaders where
122instance Default XhrResponseHeaders where
123− def = OnlyHeaders []
123+ def = OnlyHeaders mempty
124
124
125{-# DEPRECATED _xhrResponse_body "Use _xhrResponse_response or _xhrResponse_responseText instead." #-}
125{-# DEPRECATED _xhrResponse_body "Use _xhrResponse_response or _xhrResponse_responseText instead." #-}
126_xhrResponse_body :: XhrResponse -> Maybe Text
126_xhrResponse_body :: XhrResponse -> Maybe Text
@@ -181,13 +181,13 @@ newXMLHttpRequestWithError req cb = do
181 when (readyState == 4) $ do
181 when (readyState == 4) $ do
182 t <- if rt == Just XhrResponseType_Text || isNothing rt
182 t <- if rt == Just XhrResponseType_Text || isNothing rt
183 then liftIO $ xmlHttpRequestGetResponseText xhr
183 then liftIO $ xmlHttpRequestGetResponseText xhr
184− else return Nothing
184+ else return Nothing
185 r <- liftIO $ xmlHttpRequestGetResponse xhr
185 r <- liftIO $ xmlHttpRequestGetResponse xhr
186 h <- case _xhrRequestConfig_responseHeaders c of
186 h <- case _xhrRequestConfig_responseHeaders c of
187 AllHeaders -> liftIO $ parseAllHeadersString <$>
187 AllHeaders -> liftIO $ parseAllHeadersString <$>
188 xmlHttpRequestGetAllResponseHeaders xhr
188 xmlHttpRequestGetAllResponseHeaders xhr
189− OnlyHeaders xs -> liftIO $ Map.fromList <$> traverse
190− (\x -> (x,) <$> xmlHttpRequestGetResponseHeader xhr x) xs
189+ OnlyHeaders xs -> liftIO $ traverse (xmlHttpRequestGetResponseHeader xhr)
190+ (Map.fromSet id xs)
191 _ <- liftIO $ cb $ Right
191 _ <- liftIO $ cb $ Right
192 XhrResponse { _xhrResponse_status = status
192 XhrResponse { _xhrResponse_status = status
193 , _xhrResponse_statusText = statusText
193 , _xhrResponse_statusText = statusText