@@ -99,10 +99,6 @@ runSession session app = ST.evalStateT (runReaderT session app) initState
99data SRequest = SRequest
99data SRequest = SRequest
100 { simpleRequest :: Request
100 { simpleRequest :: Request
101 , simpleRequestBody :: L.ByteString
101 , simpleRequestBody :: L.ByteString
102− -- ^ Request body that will override the one set in 'simpleRequest'.
104− -- This is usually simpler than setting the body as a stateful IO-action
105− -- in 'simpleRequest'.
107data SResponse = SResponse
103data SResponse = SResponse
108 { simpleStatus :: H.Status
104 { simpleStatus :: H.Status
@@ -110,16 +106,8 @@ data SResponse = SResponse
110 , simpleBody :: L.ByteString
106 , simpleBody :: L.ByteString
112 deriving (Show, Eq)
108 deriving (Show, Eq)
114request :: Request -> Session SResponse
109request :: Request -> Session SResponse
115−request req = do
110+request = srequest . flip SRequest L.empty
117− req' <- addCookiesToRequest req
118− response <- liftIO $ do
119− ref <- newIORef $ error "runResponse gave no result"
120− ResponseReceived <- app req' (runResponse ref)
122− extractSetCookieFromSResponse response
124-- | Set whole path (request path + query string).
112-- | Set whole path (request path + query string).
125setPath :: Request -> S8.ByteString -> Request
113setPath :: Request -> S8.ByteString -> Request
@@ -178,18 +166,22 @@ extractSetCookieFromSResponse response = do
178 (Map.fromList [(Cookie.setCookieName c, c) | c <- newClientCookies ]))
166 (Map.fromList [(Cookie.setCookieName c, c) | c <- newClientCookies ]))
179 return response
167 return response
181−-- | Similar to 'request', but allows setting the request body as a plain
183srequest :: SRequest -> Session SResponse
169srequest :: SRequest -> Session SResponse
184srequest (SRequest req bod) = do
170srequest (SRequest req bod) = do
185 refChunks <- liftIO $ newIORef $ L.toChunks bod
172 refChunks <- liftIO $ newIORef $ L.toChunks bod
187− req
173+ let req' = req
188− { requestBody = atomicModifyIORef refChunks $ \bss ->
174+ { requestBody = atomicModifyIORef refChunks $ \bss ->
189− case bss of
175+ case bss of
190− [] -> ([], S.empty)
176+ [] -> ([], S.empty)
191− x:y -> (y, x)
177+ x:y -> (y, x)
179+ req'' <- addCookiesToRequest req'
180+ response <- liftIO $ do
181+ ref <- newIORef $ error "runResponse gave no result"
182+ ResponseReceived <- app req'' (runResponse ref)
184+ extractSetCookieFromSResponse response
194runResponse :: IORef SResponse -> Response -> IO ResponseReceived
186runResponse :: IORef SResponse -> Response -> IO ResponseReceived
195runResponse ref res = do
187runResponse ref res = do