]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/Postprocess.hs
Documentation
[Lucu.git] / Network / HTTP / Lucu / Postprocess.hs
index 7d7e147f93be84797d739ca976991a4954ea5929..24a07f18bb7d74af7e9ba7ac6468738633dfc0cf 100644 (file)
@@ -1,6 +1,7 @@
+-- #hide
 module Network.HTTP.Lucu.Postprocess
-    ( postprocess -- Interaction -> STM ()
-    , completeUnconditionalHeaders -- Config -> Response -> IO Response
+    ( postprocess
+    , completeUnconditionalHeaders
     )
     where
 
@@ -71,16 +72,16 @@ postprocess itr
 
                           when (not $ any (\ p -> p sc) [isSuccessful, isRedirection, isError])
                                    $ abortSTM InternalServerError []
-                                         ("The status code is not good for a final status: "
-                                          ++ show sc)
+                                         $ Just ("The status code is not good for a final status: "
+                                                 ++ show sc)
 
                           when (sc == MethodNotAllowed && getHeader "Allow" res == Nothing)
                                    $ abortSTM InternalServerError []
-                                         ("The status was " ++ show sc ++ " but no Allow header.")
+                                         $ Just ("The status was " ++ show sc ++ " but no Allow header.")
 
                           when (sc /= NotModified && isRedirection sc && getHeader "Location" res == Nothing)
                                    $ abortSTM InternalServerError []
-                                         ("The status code was " ++ show sc ++ " but no Location header.")
+                                         $ Just ("The status code was " ++ show sc ++ " but no Location header.")
 
          when (itrRequest itr /= Nothing)
               $ relyOnRequest itr
@@ -106,6 +107,10 @@ postprocess itr
 
                updateRes itr $ deleteHeader "Content-Length"
 
+               cType <- readHeader itr "Content-Type"
+               when (cType == Nothing)
+                        $ updateRes itr $ setHeader "Content-Type" "application/octet-stream"
+
                if canHaveBody then
                    do teM <- readHeader itr "Transfer-Encoding"
                       if reqVer == HttpVersion 1 1 then
@@ -117,9 +122,9 @@ postprocess itr
                                           in
                                             when (teList == [] || last teList /= "chunked")
                                                      $ abortSTM InternalServerError []
-                                                           ("Transfer-Encoding must end with `chunked' "
-                                                            ++ "because this is an HTTP/1.1 request: "
-                                                            ++ te)
+                                                           $ Just ("Transfer-Encoding must end with `chunked' "
+                                                                   ++ "because this is an HTTP/1.1 request: "
+                                                                   ++ te)
 
                              writeItr itr itrWillChunkBody True
                         else
@@ -127,13 +132,9 @@ postprocess itr
                             Nothing         -> return ()
                             Just "identity" -> return ()
                             Just te         -> abortSTM InternalServerError []
-                                                      ("Transfer-Encoding must be `identity' because "
+                                               $ Just ("Transfer-Encoding must be `identity' because "
                                                        ++ "this is an HTTP/1.0 request: "
                                                        ++ te)
-
-                      cType <- readHeader itr "Content-Type"
-                      when (cType == Nothing)
-                               $ updateRes itr $ setHeader "Content-Type" "application/octet-stream"
                  else
                    -- body 関連のヘッダを削除。但し HEAD なら Content-* は殘す
                    do updateRes itr $ deleteHeader "Transfer-Encoding"