@@ -15,10 +15,10 @@ module Network.HTTP.Affjax
1515import Control.Monad.Aff (Aff (), makeAff )
1616import Control.Monad.Eff (Eff ())
1717import Control.Monad.Eff.Exception (Error (), error )
18- import Data.Maybe (Maybe (..))
1918import Data.Either (Either (..))
2019import Data.Foreign (Foreign (..), F ())
2120import Data.Function (Fn4 (), runFn4 )
21+ import Data.Maybe (Maybe (..), maybe )
2222import Data.Nullable (Nullable (), toNullable )
2323import Network.HTTP.Affjax.Request
2424import Network.HTTP.Affjax.Response
@@ -27,6 +27,7 @@ import Network.HTTP.Method (Method(..), methodToString)
2727import Network.HTTP.RequestHeader (RequestHeader (), requestHeaderName , requestHeaderValue )
2828import Network.HTTP.ResponseHeader (ResponseHeader (), responseHeader )
2929import Network.HTTP.StatusCode (StatusCode ())
30+ import Type.Proxy (Proxy (..))
3031
3132-- | The effect type for AJAX requests made with Affjax.
3233foreign import data Ajax :: !
@@ -102,6 +103,7 @@ affjax' req eb cb =
102103 , url: req.url
103104 , headers: (\h -> { field: requestHeaderName h, value: requestHeaderValue h }) <$> req.headers
104105 , content: toNullable (toRequest <$> req.content)
106+ , responseType: responseTypeToString $ responseType (Proxy :: Proxy b )
105107 , username: toNullable req.username
106108 , password: toNullable req.password
107109 }
@@ -115,6 +117,7 @@ type AjaxRequest =
115117 , url :: URL
116118 , headers :: [{ field :: String , value :: String } ]
117119 , content :: Nullable RequestContent
120+ , responseType :: String
118121 , username :: Nullable String
119122 , password :: Nullable String
120123 }
@@ -147,7 +150,7 @@ foreign import unsafeAjax
147150 response: xhr.response
148151 })();
149152 };
150- if (options.responseType) xhr.responseType = options.responseType;
153+ xhr.responseType = options.responseType;
151154 xhr.send(options.content);
152155 };
153156 }
0 commit comments