diff --git a/Framework/Http/HTTPServer.hs b/Framework/Http/HTTPServer.hs
index 14cce06..9c70c3d 100644
--- a/Framework/Http/HTTPServer.hs
+++ b/Framework/Http/HTTPServer.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE NamedFieldPuns #-}
+-- | This module wraps Httpd
module Framework.Http.HTTPServer
(defaultURLConf,
serveHttp,
diff --git a/Framework/Http/PostParser.hs b/Framework/Http/PostParser.hs
index c6969b2..f1f8f6a 100644
--- a/Framework/Http/PostParser.hs
+++ b/Framework/Http/PostParser.hs
@@ -26,6 +26,7 @@ type FormData = [FormDataItem]
urlencoded = "application/x-www-form-urlencoded"
multipart = "multipart/form-data"
+-- | Get map of POST variables from request
_POST :: HttpRequest -> HttpVarsMap
_POST rq =
if hdr == multipart
@@ -35,6 +36,7 @@ _POST rq =
where ctype = fromMaybe urlencoded $ lookupHeader HdrContentType $ rqHeaders rq
hdr = getHeader ctype
+getUrlEncodedVars :: HttpRequest -> HttpVarsMap
getUrlEncodedVars rq = M.fromList $ map (second Str) $ decodePairs (rqBody rq)
flattenFormData :: FormData -> [(String,HttpVar)]
@@ -48,6 +50,7 @@ base s = if (length s)>=2
then (tail.init) s
else (trace (show s) [])
+parseHeaderAttrs :: String -> [(String, String)]
parseHeaderAttrs v = map parse' lst
where
lst = tail $ split "; " v
@@ -85,6 +88,7 @@ parseP part =
Nothing -> Single name $ Str $ (init.init) oth
Left err -> error "Could not parse headers!"
+cutAt :: String -> String -> (String, String)
cutAt sp str = cutAt' "" str
where
cutAt' acc [] = (acc, "")
@@ -95,8 +99,3 @@ cutAt sp str = cutAt' "" str
parse :: String -> String -> FormData
parse b str = map parseP $ map (drop 2) $ base $ split ("--"++b) str
--- s = "-----------------------------14004705096106365022051874893\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nX\r\n-----------------------------14004705096106365022051874893\r\nContent-Disposition: form-data; name=\"value\"\r\n\r\nY\r\n-----------------------------14004705096106365022051874893\r\nContent-Disposition: form-data; name=\"file\"; filename=\"missfont.log\"\r\nContent-Type: text/x-log\r\n\r\nmktextfm cmr\n\r\n-----------------------------14004705096106365022051874893--\r\n"
-
--- bound = "---------------------------14004705096106365022051874893"
-
--- main = print $ flattenFormData $ parse bound s
diff --git a/Framework/Http/Vars.hs b/Framework/Http/Vars.hs
index c9b81e1..ae1824b 100644
--- a/Framework/Http/Vars.hs
+++ b/Framework/Http/Vars.hs
@@ -1,3 +1,4 @@
+-- | This module contains functions to access HTTP GET and POST variables.
module Framework.Http.Vars
(_GET, _POST,
getVar, getVar',
@@ -19,6 +20,7 @@ import Framework.Utils
import Framework.Http.Httpd
import Framework.Http.PostParser
+-- | Get map of GET variables from request
_GET :: HttpRequest -> HttpVarsMap
_GET rq = M.fromList $ map (second Str) $ queryToArguments $ uriQuery $ rqURI rq
@@ -26,30 +28,56 @@ varToString :: HttpVar -> String
varToString (Str s) = s
varToString (POSTfile {filebody=body}) = body
-getVar :: HttpVarsMap -> String -> Maybe HttpVar
+-- | Get a variable from map
+getVar :: HttpVarsMap
+ -> String -- ^ Variable name
+ -> Maybe HttpVar
getVar = flip M.lookup
-getFile :: HttpVarsMap -> String -> Maybe HttpVar
+-- | Get a file from map
+getFile :: HttpVarsMap
+ -> String -- ^ Variable name
+ -> Maybe HttpVar
getFile mm name = toFile =<< (M.lookup name mm)
where toFile f@(POSTfile {}) = Just f
toFile (Str _) = Nothing
-getVar' :: HttpVarsMap -> String -> String -> HttpVar
+-- | Get a variable from map, with default value
+getVar' :: HttpVarsMap
+ -> String -- ^ Variable name
+ -> String -- ^ Default value
+ -> HttpVar
getVar' mm name def = fromMaybe (Str def) $ M.lookup name mm
-getString :: HttpVarsMap -> String -> Maybe String
+-- | Get a string variable from map
+getString :: HttpVarsMap
+ -> String -- ^ Variable name
+ -> Maybe String
getString mm name = varToString `fmap` (M.lookup name mm)
-getString' :: HttpVarsMap -> String -> String -> String
+-- | Same, but with default value
+getString' :: HttpVarsMap
+ -> String -- ^ Variable name
+ -> String -- ^ Default value
+ -> String
getString' mm name def = fromMaybe def $ getString mm name
-httpGetVar' :: HttpRequest -> String -> String -> String
+-- | Get string GET variable directly from request, with default value
+httpGetVar' :: HttpRequest
+ -> String -- ^ Variable name
+ -> String -- ^ Default value
+ -> String
httpGetVar' rq name def = getString' (_GET rq) name def
+-- | Get string POST variable directly from request
httpPostVar :: HttpRequest -> String -> Maybe String
httpPostVar rq name = getString (_POST rq) name
-httpPostVar' :: HttpRequest -> String -> String -> String
+-- | Same, but with default value
+httpPostVar' :: HttpRequest
+ -> String -- ^ Variable name
+ -> String -- ^ Default value
+ -> String
httpPostVar' rq name def = getString' (_POST rq) name def
-- | Add GET var to given Request and return resulting URL
diff --git a/Framework/Pager.hs b/Framework/Pager.hs
index 2327b1e..cae8d49 100644
--- a/Framework/Pager.hs
+++ b/Framework/Pager.hs
@@ -12,7 +12,6 @@ import Framework.Forms.HTML
import Framework.Models
import Framework.SQL
import Framework.API
--- import Framework.Urls
import Framework.Types
import Framework.Http.Vars
diff --git a/Framework/Types.hs b/Framework/Types.hs
index 7223341..207a39e 100644
--- a/Framework/Types.hs
+++ b/Framework/Types.hs
@@ -28,6 +28,7 @@ instance Show DBConnection where
type HttpRequest = Request String
type HttpResponse = Response String
+-- | HTTP (GET or POST) variable can contain just a string or an uploaded file.
data HttpVar = Str String
| POSTfile {
filename :: String,
@@ -49,8 +50,8 @@ data StaticConfig = HP {
cachePath :: String, -- ^ Info for cache backend
sessionsDriver :: String, -- ^ Sessions backend name
sessionsPath :: String, -- ^ Info for sessions backend
- accessLogPath :: String,
- errorsLogPath :: String,
+ accessLogPath :: String, -- ^ Path to the access log
+ errorsLogPath :: String, -- ^ Path to the erros log
dbpool :: MPool DBConnection, -- ^ DB connections pool
cpool :: MPool CacheConnection,-- ^ Cache connections pool
logChan :: Log, -- ^ Handle to log