X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FDefaultPage.hs;h=785e4c19480d385d2bc783cd441a2fc800983bf7;hb=72a3e24a952616e32845eeb4fc05048e841c91a2;hp=1e5a7a6c6e51ebc422d72db62d024f56ac93df0a;hpb=cc55fb9a095c9c583ed6fe2ded3eaf6401fb760f;p=Lucu.git diff --git a/Network/HTTP/Lucu/DefaultPage.hs b/Network/HTTP/Lucu/DefaultPage.hs index 1e5a7a6..785e4c1 100644 --- a/Network/HTTP/Lucu/DefaultPage.hs +++ b/Network/HTTP/Lucu/DefaultPage.hs @@ -1,29 +1,25 @@ {-# LANGUAGE - BangPatterns - , OverloadedStrings - , UnboxedTuples + OverloadedStrings + , RecordWildCards , UnicodeSyntax #-} module Network.HTTP.Lucu.DefaultPage ( getDefaultPage - , writeDefaultPage + , defaultPageContentType , mkDefaultPage ) where -import qualified Blaze.ByteString.Builder.Char.Utf8 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 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) @@ -35,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 ⋙ @@ -44,21 +40,13 @@ getDefaultPage !conf !req !res in Lazy.pack xmlStr -writeDefaultPage ∷ Interaction → STM () -writeDefaultPage !itr - -- Content-Type が正しくなければ補完できない。 - = do res ← readItr itrResponse itr - when (getHeader "Content-Type" res == Just defaultPageContentType) - $ do reqM ← readItr itrRequest itr - - let conf = itrConfig itr - page = getDefaultPage conf reqM res - - putTMVar (itrBodyToSend itr) (BB.fromLazyText 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 " @@ -81,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 は補完しない