@@ -68,7 +68,7 @@ data Req t = Req
6868 , qParams :: [(String, QueryPart t)]
6969 , reqBody :: Maybe (Behavior t (Either String (BL.ByteString, String)))
7070 -- , reqAccept :: [MediaType] -- TODO ?
71− , headers :: [(String, Behavior t String)]
71+ , headers :: [(String, Behavior t (Either String String))]
7272 , authData :: Maybe (Behavior t (Maybe BasicAuthData))
7373 }
7474
@@ -80,10 +80,7 @@ prependToPathParts p req =
8080 req { reqPathParts = p : reqPathParts req }
8181
8282addHeader :: (ToHttpApiData a, Reflex t) => String -> Behavior t (Either String a) -> Req t -> Req t
83−addHeader name val req = req { headers = headers req
84− ++ [(name, fmap (unpack . toHeader) val)]
85−-- ++ [(name, (fmap . fmap) (decodeUtf8 . toHeader) val)]
86− }
83+addHeader name val req = req { headers = (name, (fmap . fmap) (unpack . toHeader) val) : headers req }
8784
8885-- * performing requests
8986
@@ -140,20 +137,26 @@ performRequest reqMethod req reqHost trigger = do
140137 x </> y | ("/" `L.isSuffixOf` x) || ("/" `L.isPrefixOf` y) = x ++ y
141138 | otherwise = x ++ '/':y
142139
143− xhrHeaders :: Behavior t [(String, String)]
144− xhrHeaders = sequence $ ffor (headers req) $ \(hName, hVal) -> fmap (hName,) hVal
145−
146− mkConfigBody :: [(String,String)] -> (Either String (BL.ByteString, String)) -> Either String XhrRequestConfig
147− mkConfigBody hs rb = case rb of
148− Left e -> Left e
149− (Right (bBytes, bCT)) ->
140+ xhrHeaders :: Behavior t (Either String [(String, String)])
141+ xhrHeaders = (fmap sequence . sequence . fmap f . headers) req
142+ where
143+ f = \(headerName, behavior) ->
144+ fmap (fmap (\rightVal -> (headerName, rightVal))) behavior
145+
146+ mkConfigBody :: Either String [(String,String)] -> (Either String (BL.ByteString, String)) -> Either String XhrRequestConfig
147+ mkConfigBody ehs rb = case (ehs, rb) of
148+ (_, Left e) -> Left e
149+ (Left e, _) -> Left e
150+ (Right hs, Right (bBytes, bCT)) ->
150151 Right $ def { _xhrRequestConfig_sendData = Just (BL.unpack bBytes)
151152 , _xhrRequestConfig_headers =
152− Map.insert "Content-Type" bCT (_xhrRequestConfig_headers def)}
153+ Map.insert "Content-Type" bCT (Map.fromList hs)}
153154
154155 xhrOpts :: Behavior t (Either String XhrRequestConfig)
155156 xhrOpts = case reqBody req of
156− Nothing -> fmap (\h -> Right $ def { _xhrRequestConfig_headers = Map.fromList h }) xhrHeaders
157+ Nothing -> fmap (\ehs -> case ehs of
158+ Left e -> Left e
159+ Right hs -> Right $ def { _xhrRequestConfig_headers = Map.fromList hs }) xhrHeaders
157160 Just rBody -> liftA2 mkConfigBody xhrHeaders rBody
158161
159162 mkAuth :: Maybe BasicAuthData -> Either String XhrRequestConfig -> Either String XhrRequestConfig