on master help sign in
Defining RspNoBody for cleaner semantics. (#468)
commit82ee2ab65a741964564721323ff2ba6f03a43a57 authorKazu Yamamoto <kazu@iij.ad.jp> dateFri 4 Dec 2015, 10:22 (11 years ago) parentc9f6c8c
1 file changed+17−14
warp/Network/Wai/Handler/Warp/Response.hs+17−14
warp/Network/Wai/Handler/Warp/Response.hs+17−14
@@ -175,7 +175,7 @@ sendResponse settings conn ii req reqidxhdr src response = do
175175 T.tickle th
176176 return ret
177177 else do
178− sendResponseNoBody conn ver s hs
178+ _ <- sendRsp conn ii ver s hs RspNoBody
179179 logger req s Nothing
180180 T.tickle th
181181 return isPersist
@@ -197,10 +197,10 @@ sendResponse settings conn ii req reqidxhdr src response = do
197197 rsp = case response of
198198 ResponseFile _ _ path mPart -> RspFile path mPart mRange isHead (T.tickle th)
199199 ResponseBuilder _ _ b
200− | isHead -> RspBuilder mempty False
200+ | isHead -> RspNoBody
201201 | otherwise -> RspBuilder b needsChunked
202202 ResponseStream _ _ fb
203− | isHead -> RspBuilder mempty False
203+ | isHead -> RspNoBody
204204 | otherwise -> RspStream fb needsChunked th
205205 ResponseRaw raw _ -> RspRaw raw src (T.tickle th)
206206 ret = case response of
@@ -236,7 +236,8 @@ sanitizeHeaderValue v = case S8.lines $ S.filter (/= _cr) v of
236236
237237----------------------------------------------------------------
238238
239−data Rsp = RspFile FilePath (Maybe FilePart) (Maybe HeaderValue) Bool (IO ())
239+data Rsp = RspNoBody
240+ | RspFile FilePath (Maybe FilePart) (Maybe HeaderValue) Bool (IO ())
240241 | RspBuilder Builder Bool
241242 | RspStream StreamingBody Bool T.Handle
242243 | RspRaw (IO ByteString -> (ByteString -> IO ()) -> IO ()) (IO ByteString) (IO ())
@@ -250,6 +251,17 @@ sendRsp :: Connection
250251 -> H.ResponseHeaders
251252 -> Rsp
252253 -> IO (Maybe H.Status, Maybe Integer)
254+
255+----------------------------------------------------------------
256+
257+sendRsp conn _ ver s hs RspNoBody = do
258+ -- Not adding Content-Length.
259+ -- User agents treats it as Content-Length: 0.
260+ composeHeader ver s hs >>= connSendAll conn
261+ return (Just s, Nothing)
262+
263+----------------------------------------------------------------
264+
253265sendRsp conn ii ver s0 hs0 (RspFile path mPart mRange isHead hook) = do
254266 ex <- fileRange s0 hs0 path mPart mRange get
255267 case ex of
@@ -261,7 +273,7 @@ sendRsp conn ii ver s0 hs0 (RspFile path mPart mRange isHead hook) = do
261273 Right (s, hs, beg, len)
262274 | len >= 0 ->
263275 if isHead then
264− sendRsp conn ii ver s hs (RspBuilder mempty False)
276+ sendRsp conn ii ver s hs RspNoBody
265277 else do
266278 lheader <- composeHeader ver s hs
267279#ifdef WINDOWS
@@ -338,15 +350,6 @@ sendRsp conn _ _ _ _ (RspRaw withApp src tickle) = do
338350 return bs
339351 send bs = connSendAll conn bs >> tickle
340352
341−----------------------------------------------------------------
342−
343−sendResponseNoBody :: Connection
344− -> H.HttpVersion
345− -> H.Status
346− -> H.ResponseHeaders
347− -> IO ()
348−sendResponseNoBody conn ver s hs = composeHeader ver s hs >>= connSendAll conn
349−
350353----------------------------------------------------------------
351354----------------------------------------------------------------
352355