packages feed

hack 2009.4.52 → 2009.5.19

raw patch · 4 files changed

+52/−60 lines, 4 filesdep +bytestringPVP ok

version bump matches the API change (PVP)

Dependencies added: bytestring

API changes (from Hackage documentation)

- Hack: custom :: Env -> [(String, String)]
- Hack: hack_errors :: Env -> HackErrors
- Hack: hack_input :: Env -> String
- Hack: hack_multiprocess :: Env -> Bool
- Hack: hack_multithread :: Env -> Bool
- Hack: hack_run_once :: Env -> Bool
- Hack: hack_url_scheme :: Env -> Hack_UrlScheme
- Hack: hack_version :: Env -> [Int]
- Hack: path_info :: Env -> String
- Hack: query_string :: Env -> String
- Hack: request_method :: Env -> RequestMethod
- Hack: script_name :: Env -> String
- Hack: server_name :: Env -> String
- Hack: server_port :: Env -> Int
+ Hack: hackErrors :: Env -> HackErrors
+ Hack: hackHeaders :: Env -> [(String, String)]
+ Hack: hackInput :: Env -> ByteString
+ Hack: hackUrlScheme :: Env -> Hack_UrlScheme
+ Hack: hackVersion :: Env -> [Int]
+ Hack: pathInfo :: Env -> String
+ Hack: queryString :: Env -> String
+ Hack: requestMethod :: Env -> RequestMethod
+ Hack: scriptName :: Env -> String
+ Hack: serverName :: Env -> String
+ Hack: serverPort :: Env -> Int
- Hack: Env :: RequestMethod -> String -> String -> String -> String -> Int -> [(String, String)] -> [Int] -> Hack_UrlScheme -> String -> HackErrors -> Bool -> Bool -> Bool -> [(String, String)] -> Env
+ Hack: Env :: RequestMethod -> String -> String -> String -> String -> Int -> [(String, String)] -> [Int] -> Hack_UrlScheme -> ByteString -> HackErrors -> [(String, String)] -> Env
- Hack: Response :: Int -> [(String, String)] -> String -> Response
+ Hack: Response :: Int -> [(String, String)] -> ByteString -> Response
- Hack: body :: Response -> String
+ Hack: body :: Response -> ByteString

Files

changelog.md view
@@ -1,3 +1,12 @@+2009.5.19+---------++### Feature++* Use lazy bytestring for performance and hinting utf-8 encoding+* remove some unused fields+* use haskell naming convention+ 2009.4.52 --------- 
hack.cabal view
@@ -1,5 +1,5 @@ Name:                 hack-Version:              2009.4.52+Version:              2009.5.19 Build-type:           Simple Synopsis:             a sexy Haskell Webserver Interface Description:@@ -20,7 +20,7 @@  library   ghc-options: -Wall-  build-depends: base, data-default >= 0.2+  build-depends: base, data-default >= 0.2, bytestring   hs-source-dirs: src/   exposed-modules:                       Hack
readme.md view
@@ -26,15 +26,13 @@      import Hack     import Hack.Handler.Happstack+    import Data.ByteString.Lazy.Char8 (pack) -    hello :: Application-    hello = \env -> return $ Response -        { status  = 200-        , headers = [ ("Content-Type", "text/plain") ]-        , body    = "Hello World"-        }+    app :: Application+    app = \env -> return $+      Response 200 [ ("Content-Type", "text/plain") ] (pack "Hello World") -    main = run hello+    main = run app  1 minute tutorial -----------------@@ -45,9 +43,7 @@      ### install hack -    cabal install happy     cabal install hack-    cabal install hack-contrib  ### pick a backend @@ -62,14 +58,14 @@     import Hack     import Hack.Handler.Happstack -    hello :: Application-    hello = \env -> return $ Response +    app :: Application+    app = \env -> return $ Response          { status  = 200         , headers = [ ("Content-Type", "text/plain") ]         , body    = "Hello World"         } -    main = run hello+    main = run app   ### run@@ -84,6 +80,13 @@  ### demo usage of middleware +install hack-contrib:++    cabal install happy+    cabal install hack-contrib++put the following in `Main.hs`. The code uses the `SimpleRouter` middleware to route both `/hello` and `/there` to the `hello` application.+     module Main where      import Hack@@ -97,7 +100,7 @@     hello = \env -> return $ def {body = show env}      app :: Application-    app = route [("/hello", hello), ("", hello)] empty_app+    app = route [("/hello", hello), ("/there", hello)] empty_app      main = run app @@ -159,26 +162,7 @@ Spec ---- -Hack spec = Rack spec :) --Please read [The Rack interface specification](http://rack.rubyforge.org/doc/files/SPEC.html).--Tip------### encoding can be tricky-1. hack uses utf8 bytes for IO-2. when dealing with html, sometimes, e.g. using template haskell, you have to -   1. encode unicode string using: `escape_unicode_xml` for plain text-   2. before rendering to response body, do `unescape_unicode_xml`-   3. then use `u2b` to convert unicode string to utf8 bytes, and push to response-3. see, xml encoding and utf8 byte encoding are different, so we need-   to convert twice-4. why bother `unescape_unicode_xml` at all? since we want the user-   to be able to see unicode chars when viewing source!-5. these helpers are in `hack-contrib` and `mps`-6. the default error stream in hack takes unicode string as input. It will be-   fixed in the next release.+See [hack doc](http://hackage.haskell.org/packages/archive/hack/2009.4.52/doc/html/Hack.html)  Links -----@@ -198,5 +182,4 @@ * [Chris Done's Blog @Kibro](http://chrisdone.com/blog/tags/Kibro.html) * [Hyena](http://github.com/tibbe/hyena/tree/master) * [Happstack](http://happstack.com/)-* [Jinjing's Blog @Hack](http://jinjing.easymic.com/tag/Hack) * [Bamboo blog engine](https://github.com/nfjinjing/bamboo/tree)
src/Hack.hs view
@@ -5,9 +5,10 @@  import Data.Default import System.IO+import qualified Data.ByteString.Lazy as B  version :: [Int]-version = [2009, 4, 52]+version = [2009, 5, 19]  data RequestMethod =      OPTIONS@@ -29,28 +30,27 @@   show _ = "HackErrors"  data Env = Env -  {  request_method :: RequestMethod            -- ^ HTTP request method  -  ,  script_name :: String                      -- ^ The initial portion of the request URL's \"path\" that corresponds to the application object, so that the application knows its virtual \"location\". This may be an empty string, if the application corresponds to the \"root\" of the server.   -  ,  path_info :: String                        -- ^ The remainder of the request URL's \"path\", designating the virtual \"location\" of the request's target within the application. This will always starts with \"/\"-  ,  query_string :: String                     -- ^ The portion of the request URL that follows the ?, if any. May be empty-  ,  server_name :: String                      -- ^ When combined with SCRIPT_NAME and PATH_INFO, these variables can be used to complete the URL. Note, however, that HTTP_HOST, if present, should be used -  ,  server_port :: Int                         -- ^ preference to SERVER_NAME for reconstructing the request URL. SERVER_NAME and SERVER_PORT can never be empty strings, and so are always required.    -  ,  http :: [(String, String)]                 -- ^ Variables corresponding to the client-supplied HTTP request headers-  ,  hack_version :: [Int]                      -- ^ The Array [0,1], representing this version of Hack-  ,  hack_url_scheme :: Hack_UrlScheme          -- ^ HTTP or HTTPS, depending on the request URL-  ,  hack_input :: String                       -- ^ body of the request-  ,  hack_errors :: HackErrors                  -- ^ error stream-  ,  hack_multithread :: Bool                   -- ^ true if the application object may be simultaneously invoked by another thread in the same process, false otherwise. -  ,  hack_multiprocess :: Bool                  -- ^ true if an equivalent application object may be simultaneously invoked by another process, false otherwise.-  ,  hack_run_once :: Bool                      -- ^ true if the server expects (but does not guarantee!) that the application will only be invoked this one time during the life of its containing process. Normally, this will only be true for a server based on CGI (or something similar). -  ,  custom :: [(String, String)]               -- ^ any non HTTP standard header+  {  requestMethod :: RequestMethod            -- ^ HTTP request method  +  ,  scriptName :: String                      -- ^ The initial portion of the request URL's \"path\" that corresponds to the application object, so that the application knows its virtual \"location\". This may be an empty string, if the application corresponds to the \"root\" of the server.   +  ,  pathInfo :: String                        -- ^ The remainder of the request URL's \"path\", designating the virtual \"location\" of the request's target within the application. This will always starts with \"/\"+  ,  queryString :: String                     -- ^ The portion of the request URL that follows the ?, if any. May be empty+  ,  serverName :: String                      -- ^ When combined with SCRIPT_NAME and PATH_INFO, these variables can be used to complete the URL. Note, however, that HTTP_HOST, if present, should be used+  ,  serverPort :: Int                         -- ^ preference to SERVER_NAME for reconstructing the request URL. SERVER_NAME and SERVER_PORT can never be empty strings, and so are always required.+  ,  http    :: [(String, String)]              -- ^ All http header variables.+  ,  hackVersion :: [Int]                      -- ^ The Array [0,1], representing this version of Hack+  ,  hackUrlScheme :: Hack_UrlScheme          -- ^ HTTP or HTTPS, depending on the request URL+  ,  hackInput :: B.ByteString              -- ^ body of the request+  ,  hackErrors :: HackErrors                  -- ^ error stream+  ,  hackHeaders    :: [(String, String)]      -- ^ custom headers, intended to be used by middleware   }-  deriving (Show)+  deriving (Show) -- careful with showing this, it now causes an infinite+                  -- loop with certain handlers due to the use of a+                  -- lazy bytestring -data Response = Response -  {  status :: Int                              -- ^ must be greater than or equal to 100. -  ,  headers :: [(String, String)]              -- ^ The header must not contain a Status key, contain keys with : or newlines in their name, contain keys names that end in - or _, but only contain keys that consist of letters, digits, _ or - and start with a letter. The values of the header must be Strings, consisting of lines (for multiple header values) seperated by \"\\n\". The lines must not contain characters below 037. -  ,  body :: String                             -- ^ body of the response+data Response = Response+  {  status :: Int                              -- ^ must be greater than or equal to 100.+  ,  headers :: [(String, String)]              -- ^ The header must not contain a Status key, contain keys with : or newlines in their name, contain keys names that end in - or _, but only contain keys that consist of letters, digits, _ or - and start with a letter. The values of the header must be Strings, consisting of lines (for multiple header values) seperated by \"\\n\". The lines must not contain characters below 037.+  ,  body :: B.ByteString                       -- ^ body of the response   }   deriving (Show) @@ -61,11 +61,11 @@   def = HTTP  instance Default Response where-  def = Response def def def+  def = Response def def B.empty  instance Default Env where-  def = Env def def def def def def def version def def stderr_stream False False False def-    where stderr_stream = hPutStr stderr+  def = Env def def def def def def def version def B.empty stderrStream def+    where stderrStream = hPutStr stderr  type Application = Env -> IO Response