X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FDefaultPage.hs;h=785e4c19480d385d2bc783cd441a2fc800983bf7;hb=72a3e24;hp=c315424414857aba8b5ffe0d1047dac10c0db5bb;hpb=0ff03469c29b791f2c609a659bbf59be97e306f2;p=Lucu.git diff --git a/Network/HTTP/Lucu/DefaultPage.hs b/Network/HTTP/Lucu/DefaultPage.hs index c315424..785e4c1 100644 --- a/Network/HTTP/Lucu/DefaultPage.hs +++ b/Network/HTTP/Lucu/DefaultPage.hs @@ -1,30 +1,25 @@ {-# LANGUAGE - BangPatterns - , OverloadedStrings - , UnboxedTuples + OverloadedStrings + , RecordWildCards , UnicodeSyntax #-} module Network.HTTP.Lucu.DefaultPage ( getDefaultPage - , writeDefaultPage + , defaultPageContentType , mkDefaultPage ) where -import qualified Blaze.ByteString.Builder.ByteString as BB import Control.Arrow import Control.Arrow.ArrowList import Control.Arrow.ListArrow import Control.Arrow.Unicode -import Control.Concurrent.STM -import Control.Monad +import Data.Ascii (Ascii) import qualified Data.Ascii as A import Data.Maybe import qualified Data.Text as T import qualified Data.Text.Lazy as Lazy -import qualified Data.Text.Lazy.Encoding as Lazy import Network.HTTP.Lucu.Config import Network.HTTP.Lucu.Headers -import Network.HTTP.Lucu.Interaction import Network.HTTP.Lucu.Request import Network.HTTP.Lucu.Response import Network.URI hiding (path) @@ -36,7 +31,7 @@ import Text.XML.HXT.DOM.TypeDefs getDefaultPage ∷ Config → Maybe Request → Response → Lazy.Text {-# INLINEABLE getDefaultPage #-} -getDefaultPage !conf !req !res +getDefaultPage conf req res = let msgA = getMsg req res [xmlStr] = runLA ( mkDefaultPage conf (resStatus res) msgA ⋙ @@ -45,22 +40,13 @@ getDefaultPage !conf !req !res in Lazy.pack xmlStr -writeDefaultPage ∷ Interaction → STM () -writeDefaultPage !itr - -- Content-Type が正しくなければ補完できない。 - = do res ← readItr itrResponse id itr - when (getHeader "Content-Type" res == Just defaultPageContentType) - $ do reqM ← readItr itrRequest id itr - - let conf = itrConfig itr - page = getDefaultPage conf reqM res - - putTMVar (itrBodyToSend itr) - (BB.fromLazyByteString $ Lazy.encodeUtf8 page) +defaultPageContentType ∷ Ascii +{-# INLINE defaultPageContentType #-} +defaultPageContentType = "application/xhtml+xml" mkDefaultPage ∷ (ArrowXml a) ⇒ Config → StatusCode → a b XmlTree → a b XmlTree {-# INLINEABLE mkDefaultPage #-} -mkDefaultPage !conf !status !msgA +mkDefaultPage conf status msgA = let sStr = A.toString $ A.fromAsciiBuilder $ printStatusCode status sig = concat [ A.toString (cnfServerSoftware conf) , " at " @@ -83,7 +69,7 @@ mkDefaultPage !conf !status !msgA getMsg ∷ (ArrowXml a) ⇒ Maybe Request → Response → a b XmlTree {-# INLINEABLE getMsg #-} -getMsg !req !res +getMsg req res = case resStatus res of -- 1xx は body を持たない -- 2xx の body は補完しない