on master help sign in
refactoring.
c4c3446Kazu Yamamoto
warp/Network/Wai/Handler/Warp/Response.hs+15−18
@@ -144,14 +144,14 @@ sendResponse settings conn ii req reqidxhdr src response = do
144 -- and status, the response to HEAD is processed here.
144 -- and status, the response to HEAD is processed here.
145 --
145 --
146 -- See definition of rsp below for proper body stripping.
146 -- See definition of rsp below for proper body stripping.
147− (ms, mlen) <- sendRsp conn ii req ver s hs rsp
147+ (ms, mlen) <- sendRsp conn ii ver s hs rsp
148 case ms of
148 case ms of
149 Nothing -> return ()
149 Nothing -> return ()
150 Just realStatus -> logger req realStatus mlen
150 Just realStatus -> logger req realStatus mlen
151 T.tickle th
151 T.tickle th
152 return ret
152 return ret
153 else do
153 else do
154− _ <- sendRsp conn ii req ver s hs RspNoBody
154+ _ <- sendRsp conn ii ver s hs RspNoBody
155 logger req s Nothing
155 logger req s Nothing
156 T.tickle th
156 T.tickle th
157 return isPersist
157 return isPersist
@@ -221,7 +221,6 @@ data Rsp = RspNoBody
221
221
222sendRsp :: Connection
222sendRsp :: Connection
223 -> InternalInfo
223 -> InternalInfo
224− -> Request
225 -> H.HttpVersion
224 -> H.HttpVersion
226 -> H.Status
225 -> H.Status
227 -> H.ResponseHeaders
226 -> H.ResponseHeaders
@@ -230,7 +229,7 @@ sendRsp :: Connection
230
229
231----------------------------------------------------------------
230----------------------------------------------------------------
232
231
233−sendRsp conn _ _ ver s hs RspNoBody = do
232+sendRsp conn _ ver s hs RspNoBody = do
234 -- Not adding Content-Length.
233 -- Not adding Content-Length.
235 -- User agents treats it as Content-Length: 0.
234 -- User agents treats it as Content-Length: 0.
236 composeHeader ver s hs >>= connSendAll conn
235 composeHeader ver s hs >>= connSendAll conn
@@ -238,7 +237,7 @@ sendRsp conn _ _ ver s hs RspNoBody = do
238
237
239----------------------------------------------------------------
238----------------------------------------------------------------
240
239
241−sendRsp conn _ _ ver s hs (RspBuilder body needsChunked) = do
240+sendRsp conn _ ver s hs (RspBuilder body needsChunked) = do
242 header <- composeHeaderBuilder ver s hs needsChunked
241 header <- composeHeaderBuilder ver s hs needsChunked
243 let hdrBdy
242 let hdrBdy
244 | needsChunked = header <> chunkedTransferEncoding body
243 | needsChunked = header <> chunkedTransferEncoding body
@@ -251,7 +250,7 @@ sendRsp conn _ _ ver s hs (RspBuilder body needsChunked) = do
251
250
252----------------------------------------------------------------
251----------------------------------------------------------------
253
252
254−sendRsp conn _ _ ver s hs (RspStream streamingBody needsChunked th) = do
253+sendRsp conn _ ver s hs (RspStream streamingBody needsChunked th) = do
255 header <- composeHeaderBuilder ver s hs needsChunked
254 header <- composeHeaderBuilder ver s hs needsChunked
256 (recv, finish) <- newBlazeRecv $ reuseBufferStrategy
255 (recv, finish) <- newBlazeRecv $ reuseBufferStrategy
257 $ toBuilderBuffer (connWriteBuffer conn) (connBufferSize conn)
256 $ toBuilderBuffer (connWriteBuffer conn) (connBufferSize conn)
@@ -275,7 +274,7 @@ sendRsp conn _ _ ver s hs (RspStream streamingBody needsChunked th) = do
275
274
276----------------------------------------------------------------
275----------------------------------------------------------------
277
276
278−sendRsp conn _ _ _ _ _ (RspRaw withApp src tickle) = do
277+sendRsp conn _ _ _ _ (RspRaw withApp src tickle) = do
279 withApp recv send
278 withApp recv send
280 return (Nothing, Nothing)
279 return (Nothing, Nothing)
281 where
280 where
@@ -289,8 +288,8 @@ sendRsp conn _ _ _ _ _ (RspRaw withApp src tickle) = do
289
288
290-- Sophisticated WAI applications.
289-- Sophisticated WAI applications.
291-- We respect s0. s0 MUST be a proper value.
290-- We respect s0. s0 MUST be a proper value.
292−sendRsp conn ii req ver s0 hs0 (RspFile path (Just part) _ isHead hook) =
291+sendRsp conn ii ver s0 hs0 (RspFile path (Just part) _ isHead hook) =
293− sendRspFile2XX conn ii req ver s0 hs path beg len isHead hook
292+ sendRspFile2XX conn ii ver s0 hs path beg len isHead hook
294 where
293 where
295 beg = filePartOffset part
294 beg = filePartOffset part
296 len = filePartByteCount part
295 len = filePartByteCount part
@@ -300,23 +299,22 @@ sendRsp conn ii req ver s0 hs0 (RspFile path (Just part) _ isHead hook) =
300
299
301-- Simple WAI applications.
300-- Simple WAI applications.
302-- Status is ignored
301-- Status is ignored
303−sendRsp conn ii req ver _ hs0 (RspFile path Nothing idxhdr isHead hook) = do
302+sendRsp conn ii ver _ hs0 (RspFile path Nothing idxhdr isHead hook) = do
304 efinfo <- E.try $ getFileInfo ii path
303 efinfo <- E.try $ getFileInfo ii path
305 case efinfo of
304 case efinfo of
306 Left (_ex :: E.IOException) ->
305 Left (_ex :: E.IOException) ->
307#ifdef WARP_DEBUG
306#ifdef WARP_DEBUG
308 print _ex >>
307 print _ex >>
309#endif
308#endif
310− sendRspFile404 conn ii req ver hs0
309+ sendRspFile404 conn ii ver hs0
311 Right finfo -> case conditionalRequest finfo hs0 idxhdr of
310 Right finfo -> case conditionalRequest finfo hs0 idxhdr of
312− WithoutBody s -> sendRsp conn ii req ver s hs0 RspNoBody
311+ WithoutBody s -> sendRsp conn ii ver s hs0 RspNoBody
313− WithBody s hs beg len -> sendRspFile2XX conn ii req ver s hs path beg len isHead hook
312+ WithBody s hs beg len -> sendRspFile2XX conn ii ver s hs path beg len isHead hook
314
313
315----------------------------------------------------------------
314----------------------------------------------------------------
316
315
317sendRspFile2XX :: Connection
316sendRspFile2XX :: Connection
318 -> InternalInfo
317 -> InternalInfo
319− -> Request
320 -> H.HttpVersion
318 -> H.HttpVersion
321 -> H.Status
319 -> H.Status
322 -> H.ResponseHeaders
320 -> H.ResponseHeaders
@@ -326,8 +324,8 @@ sendRspFile2XX :: Connection
326 -> Bool
324 -> Bool
327 -> IO ()
325 -> IO ()
328 -> IO (Maybe H.Status, Maybe Integer)
326 -> IO (Maybe H.Status, Maybe Integer)
329−sendRspFile2XX conn ii req ver s hs path beg len isHead hook
327+sendRspFile2XX conn ii ver s hs path beg len isHead hook
330− | isHead = sendRsp conn ii req ver s hs RspNoBody
328+ | isHead = sendRsp conn ii ver s hs RspNoBody
331 | otherwise = do
329 | otherwise = do
332 lheader <- composeHeader ver s hs
330 lheader <- composeHeader ver s hs
333 (mfd, fresher) <- getFd ii path
331 (mfd, fresher) <- getFd ii path
@@ -338,11 +336,10 @@ sendRspFile2XX conn ii req ver s hs path beg len isHead hook
338
336
339sendRspFile404 :: Connection
337sendRspFile404 :: Connection
340 -> InternalInfo
338 -> InternalInfo
341− -> Request
342 -> H.HttpVersion
339 -> H.HttpVersion
343 -> H.ResponseHeaders
340 -> H.ResponseHeaders
344 -> IO (Maybe H.Status, Maybe Integer)
341 -> IO (Maybe H.Status, Maybe Integer)
345−sendRspFile404 conn ii req ver hs0 = sendRsp conn ii req ver s hs (RspBuilder body True)
342+sendRspFile404 conn ii ver hs0 = sendRsp conn ii ver s hs (RspBuilder body True)
346 where
343 where
347 s = H.notFound404
344 s = H.notFound404
348 hs = replaceHeader H.hContentType "text/plain; charset=utf-8" hs0
345 hs = replaceHeader H.hContentType "text/plain; charset=utf-8" hs0