5 module Network.HTTP.Lucu.DefaultPage
7 , defaultPageContentType
12 import Control.Arrow.ArrowList
13 import Control.Arrow.ListArrow
14 import Control.Arrow.Unicode
15 import Data.Ascii (Ascii)
16 import qualified Data.Ascii as A
18 import qualified Data.Text as T
19 import qualified Data.Text.Lazy as Lazy
20 import Network.HTTP.Lucu.Config
21 import Network.HTTP.Lucu.Headers
22 import Network.HTTP.Lucu.Request
23 import Network.HTTP.Lucu.Response
24 import Network.URI hiding (path)
25 import Prelude.Unicode
26 import Text.XML.HXT.Arrow.WriteDocument
27 import Text.XML.HXT.Arrow.XmlArrow
28 import Text.XML.HXT.Arrow.XmlState
29 import Text.XML.HXT.DOM.TypeDefs
31 getDefaultPage ∷ Config → Maybe Request → Response → Lazy.Text
32 {-# INLINEABLE getDefaultPage #-}
33 getDefaultPage conf req res
34 = let msgA = getMsg req res
35 [xmlStr] = runLA ( mkDefaultPage conf (resStatus res) msgA
37 writeDocumentToString [ withIndent True ]
42 defaultPageContentType ∷ Ascii
43 {-# INLINE defaultPageContentType #-}
44 defaultPageContentType = "application/xhtml+xml"
46 mkDefaultPage ∷ (ArrowXml a) ⇒ Config → StatusCode → a b XmlTree → a b XmlTree
47 {-# INLINEABLE mkDefaultPage #-}
48 mkDefaultPage conf status msgA
49 = let sStr = A.toString $ A.fromAsciiBuilder $ printStatusCode status
50 sig = concat [ A.toString (cnfServerSoftware conf)
52 , T.unpack (cnfServerHost conf)
56 += sattr "xmlns" "http://www.w3.org/1999/xhtml"
65 += ( eelem "p" += msgA )
67 += ( eelem "address" += txt sig ))))
69 getMsg ∷ (ArrowXml a) ⇒ Maybe Request → Response → a b XmlTree
70 {-# INLINEABLE getMsg #-}
72 = case resStatus res of
78 → txt ("The resource at " ⧺ path ⧺ " has been moved to ")
80 eelem "a" += sattr "href" loc
86 → txt ("The resource at " ⧺ path ⧺ " is currently located at ")
88 eelem "a" += sattr "href" loc
91 txt ". This is not a permanent relocation."
94 → txt ("The resource at " ⧺ path ⧺ " can be found at ")
96 eelem "a" += sattr "href" loc
102 → txt ("The resource at " ⧺ path ⧺ " is temporarily located at ")
104 eelem "a" += sattr "href" loc
111 → txt "The server could not understand the request you sent."
114 → txt ("You need a valid authentication to access " ⧺ path)
117 → txt ("You don't have permission to access " ⧺ path)
120 → txt ("The requested URL " ⧺ path ⧺ " was not found on this server.")
123 → txt ("The resource at " ⧺ path ⧺ " was here in past times, but has gone permanently.")
125 RequestEntityTooLarge
126 → txt ("The request entity you sent for " ⧺ path ⧺ " was too large to accept.")
129 → txt "The request URI you sent was too large to accept."
133 → txt ("An internal server error has occured during the process of your request to " ⧺ path)
136 → txt "The service is temporarily unavailable. Try later."
142 path = let uri = reqURI $ fromJust req
147 loc = A.toString $ fromJust $ getHeader "Location" res