X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FInteraction.hs;h=d36c4d1773d4ebcaad2cf2937d5ce0fcddf716b0;hp=0f3e7bfeae5492a73edddd387528d9368dca57e8;hb=b5dc373;hpb=57b93dc50655857941cc176aed2fc085e6555ff7 diff --git a/Network/HTTP/Lucu/Interaction.hs b/Network/HTTP/Lucu/Interaction.hs index 0f3e7bf..d36c4d1 100644 --- a/Network/HTTP/Lucu/Interaction.hs +++ b/Network/HTTP/Lucu/Interaction.hs @@ -33,10 +33,12 @@ import Control.Applicative import Control.Concurrent.STM import Data.Ascii (Ascii) import Data.ByteString (ByteString) +import Data.Convertible.Base import Data.Monoid.Unicode +import Data.Proxy import Data.Sequence (Seq) import Data.Time -import qualified Data.Time.HTTP as HTTP +import Data.Time.Format.HTTP import Data.Typeable import Network.Socket import Network.HTTP.Lucu.Config @@ -49,6 +51,7 @@ import Network.HTTP.Lucu.Utils #if defined(HAVE_SSL) import OpenSSL.X509 #endif +import Prelude.Unicode class Typeable i ⇒ Interaction i where toInteraction ∷ i → SomeInteraction @@ -85,13 +88,13 @@ instance Interaction SyntacticallyInvalidInteraction mkSyntacticallyInvalidInteraction ∷ Config → IO SyntacticallyInvalidInteraction -mkSyntacticallyInvalidInteraction config@(Config {..}) +mkSyntacticallyInvalidInteraction conf@(Config {..}) = do date ← getCurrentDate let res = setHeader "Server" cnfServerSoftware $ setHeader "Date" date $ setHeader "Content-Type" defaultPageContentType $ emptyResponse BadRequest - body = getDefaultPage config Nothing res + body = defaultPageForResponse conf Nothing res return SYI { syiResponse = res , syiBodyToSend = body @@ -123,8 +126,16 @@ mkSemanticallyInvalidInteraction config@(Config {..}) (AugmentedRequest {..}) let res = setHeader "Server" cnfServerSoftware $ setHeader "Date" date $ setHeader "Content-Type" defaultPageContentType $ + ( if arWillChunkBody + then setHeader "Transfer-Encoding" "chunked" + else id + ) $ + ( if arWillClose + then setHeader "Connection" "close" + else id + ) $ emptyResponse arInitialStatus - body = getDefaultPage config (Just arRequest) res + body = defaultPageForResponse config (Just arRequest) res return SEI { seiRequest = arRequest , seiExpectedContinue = arExpectedContinue @@ -236,7 +247,9 @@ mkNormalInteraction config remoteAddr (AugmentedRequest {..}) rsrcPath type InteractionQueue = TVar (Seq SomeInteraction) mkInteractionQueue ∷ IO InteractionQueue +{-# INLINE mkInteractionQueue #-} mkInteractionQueue = newTVarIO (∅) getCurrentDate ∷ IO Ascii -getCurrentDate = HTTP.toAscii <$> getCurrentTime +{-# INLINE getCurrentDate #-} +getCurrentDate = flip proxy http ∘ cs <$> getCurrentTime