Name: Lucu
-Synopsis: HTTP Daemon Library
+Synopsis: HTTP Daemonic Library
Version: 0.1
License: PublicDomain
Author: PHO
Build-Depends:
base, mtl, network, stm, parsec, hxt, haskell-src, unix
Exposed-Modules:
+ Network.HTTP.Lucu
Network.HTTP.Lucu.Abortion
Network.HTTP.Lucu.Chunk
Network.HTTP.Lucu.Config
Network.HTTP.Lucu.ResponseWriter
Network.HTTP.Lucu.StaticFile
Network.HTTP.Lucu.Utils
-ghc-options: -threaded -fglasgow-exts
+ghc-options: -threaded -fglasgow-exts -O3
-Executable: HelloWorld
-Main-Is: HelloWorld.hs
-Hs-Source-Dirs: ., examples
-ghc-options: -threaded -fglasgow-exts
\ No newline at end of file
+--Executable: HelloWorld
+--Main-Is: HelloWorld.hs
+--Hs-Source-Dirs: ., examples
+--ghc-options: -threaded -fglasgow-exts
\ No newline at end of file
rm -rf dist Setup Setup.o Setup.hi .setup-config
find . -name '*~' -exec rm -f {} \;
+doc:
+ ./Setup haddock
+
install: build
./Setup install
-.PHONY: run build clean install
\ No newline at end of file
+.PHONY: run build clean install doc
\ No newline at end of file
--- /dev/null
+module Network.HTTP.Lucu
+ ( -- Abortion
+ abort
+ , abortA
+
+ -- Config
+ , Config(..)
+ , defaultConfig
+
+ -- ETag
+ , ETag
+ , mkETag
+ , strongETag
+ , weakETag
+
+ -- Httpd
+ , runHttpd
+
+ -- MIMEType
+ , MIMEType(..)
+ , (+/+)
+ , (+:+)
+ , (+=+)
+
+ -- Request
+ , Method(..)
+ , Request(..)
+
+ -- Resource (driftTo だけは要らないが)
+ , module Network.HTTP.Lucu.Resource
+
+ -- Resource.Tree
+ , ResourceDef(..)
+ , ResTree
+ , mkResTree
+
+ -- Response
+ , StatusCode(..)
+
+ -- StaticFile
+ , module Network.HTTP.Lucu.StaticFile
+ )
+ where
+
+import Network.HTTP.Lucu.Abortion
+import Network.HTTP.Lucu.Config
+import Network.HTTP.Lucu.ETag
+import Network.HTTP.Lucu.Httpd
+import Network.HTTP.Lucu.MIMEType
+import Network.HTTP.Lucu.Request
+import Network.HTTP.Lucu.Resource
+import Network.HTTP.Lucu.Resource.Tree
+import Network.HTTP.Lucu.Response
+import Network.HTTP.Lucu.StaticFile
-- がある。
abortPage :: Config -> Maybe Request -> Maybe Response -> Abortion -> String
abortPage conf reqM resM abo
- = let msg = case aboMessage abo of
- Just msg -> msg
- Nothing -> let res' = case resM of
- Just res -> res { resStatus = aboStatus abo }
- Nothing -> Response {
- resVersion = HttpVersion 1 1
- , resStatus = aboStatus abo
- , resHeaders = []
- }
- res = foldl (.) id [setHeader name value
- | (name, value) <- aboHeaders abo]
- $ res'
- in
- getDefaultPage conf reqM res
- [html] = unsafePerformIO
- $ runX ( mkDefaultPage conf (aboStatus abo) (txt msg)
- >>>
- writeDocumentToString [(a_indent, v_1)]
- )
- in
- html
+ = case aboMessage abo of
+ Just msg
+ -> let [html] = unsafePerformIO
+ $ runX ( mkDefaultPage conf (aboStatus abo) (txt msg)
+ >>>
+ writeDocumentToString [(a_indent, v_1)]
+ )
+ in
+ html
+ Nothing
+ -> let res' = case resM of
+ Just res -> res { resStatus = aboStatus abo }
+ Nothing -> Response {
+ resVersion = HttpVersion 1 1
+ , resStatus = aboStatus abo
+ , resHeaders = []
+ }
+ res = foldl (.) id [setHeader name value
+ | (name, value) <- aboHeaders abo]
+ $ res'
+ in
+ getDefaultPage conf reqM res
module Network.HTTP.Lucu.Resource.Tree
( ResourceDef(..)
- , Resource
, ResTree
, mkResTree -- [ ([String], ResourceDef) ] -> ResTree
import Prelude hiding (catch)
-{- /aaa/bbb/ccc にアクセスされた時、もし /aaa/bbb に貪欲なリソースがあ
- れば、假に /aaa/bbb/ccc に何らかのリソースがあったとしても必ず
- /aaa/bbb が撰ばれる。/aaa/bbb のリソースが貪欲でなければ、それは無視
- される。 -}
+-- "/aaa/bbb/ccc" にアクセスされた時、もし "/aaa/bbb" に貪欲なリソース
+-- があれば、假に "/aaa/bbb/ccc" に何らかのリソースがあったとしても必ず
+-- "/aaa/bbb" が撰ばれる。"/aaa/bbb" のリソースが貪欲でなければ、それは
+-- 無視される。
data ResourceDef = ResourceDef {
resUsesNativeThread :: Bool
, resIsGreedy :: Bool
children = processNonRoot nonRoots
in
if null roots then
- -- / にリソースが定義されない。/foo とかにはあるかも。
+ -- "/" にリソースが定義されない。"/foo" とかにはあるかも。
ResNode Nothing children
else
- -- / がある。
+ -- "/" がある。
let (_, def) = last roots
in
ResNode (Just def) children
resUsesNativeThread = False
, resIsGreedy = False
, resGet
- = Just $ do time <- liftIO $ getClockTime
- foundEntity (strongETag "abcde") time
+ = Just $ do --time <- liftIO $ getClockTime
+ --foundEntity (strongETag "abcde") time
setContentType $ "text" +/+ "hello"
outputChunk "Hello, "
outputChunk "World!\n"