Ketchup 0.3.1 → 0.4.0
raw patch · 61 files changed
+97/−50 lines, 61 filesdep −regex-pcre-builtinbinary-addedPVP ok
version bump matches the API change (PVP)
Dependencies removed: regex-pcre-builtin
API changes (from Hackage documentation)
Files
- .git/COMMIT_EDITMSG +15/−1
- .git/FETCH_HEAD +2/−2
- .git/ORIG_HEAD +1/−1
- .git/index binary
- .git/logs/HEAD +2/−0
- .git/logs/refs/heads/master +2/−0
- .git/logs/refs/remotes/origin/gh-pages +1/−0
- .git/logs/refs/remotes/origin/master +2/−0
- .git/objects/04/27491eaa020186e459934ed69cdb7d808501cd +4/−0
- .git/objects/04/a409a115341e8d88fbe81afe993e824ed5a755 binary
- .git/objects/0b/1732fd47a5b9008302f3cf2cc815b4c3fcbb03 binary
- .git/objects/0e/f0bb4acb2a054328faea81aaa1b6ef08ab4324 binary
- .git/objects/2b/9c68df7936d7398cd61b39686392d66ff8f1c1 binary
- .git/objects/31/0e7b443f14a92b46059c540620e2e3ec9eeecf binary
- .git/objects/33/d1dadf72d9a1c6217c5a6c7992dcdaaa343742 binary
- .git/objects/34/f107591ec1e00bba2a7bee5238bddbb4832bdb binary
- .git/objects/39/7b16f4af94e0b04d7e6c7063332150ee9113e1 binary
- .git/objects/4c/2353910734c89633d869f0ffccf8f565c93221 +2/−0
- .git/objects/5c/7dd6782bd7103baeb041d69fd3e17410ab46dd binary
- .git/objects/63/50f4f119a8325852c5279f96ae5b0c34cce55f binary
- .git/objects/6c/fe3c139d7fb98d3057452404339c790f2aa1d3 binary
- .git/objects/70/15cd0af9b0fc60257cff8d057cee6a475f44d8 binary
- .git/objects/83/ac9915be5493cf66f1f96de88b5edce6c39929 +1/−0
- .git/objects/85/b4c8d2256c11c570cacf64895353c0b9bd374f +2/−0
- .git/objects/87/66065959fca5de5327f875dbb67559f69b52b6 +3/−0
- .git/objects/a3/3f00a997926762956b66487bc763c7500b5912 binary
- .git/objects/ad/296ab5c62662ad2f55c20cd75483c7014e3a9e binary
- .git/objects/c4/41d386e187efdfa3b1992b4bd4406bd9a2ad0d binary
- .git/objects/c8/298c807614715a3dd52fe3fddcd74b42d8dd51 binary
- .git/objects/ca/7171c6a9384a3af595c1110538b011803b834c binary
- .git/objects/cc/746e214c400d625c17bb704964d2490009dcd6 binary
- .git/objects/da/b38cfd353bbdc462641543658ea8acd3eac19d binary
- .git/objects/e5/afddd93fed2971b278890973cea1740b8011a2 binary
- .git/objects/e5/dc6abf9873d9eaf80c4e5d308832b23e5b18cd binary
- .git/objects/e8/a9b100db71a644cc6cf513f26b5f44a42d17ab binary
- .git/objects/ec/a1b33fcd1c0373e31d108a81dca8be042fd89c binary
- .git/objects/f6/e848cb8cee1bc156a72f65022e443a068cae23 binary
- .git/objects/f8/b79cfde7e99e07a48a906d6b0f43517cdee2b3 binary
- .git/objects/ff/6a9f5d733cd98051951968bb686e9766cf0a44 binary
- .git/refs/heads/master +1/−1
- .git/refs/remotes/origin/gh-pages +1/−1
- .git/refs/remotes/origin/master +1/−1
- Ketchup.cabal +2/−5
- Ketchup/Auth.hi binary
- Ketchup/Auth.o binary
- Ketchup/Chunked.hi binary
- Ketchup/Chunked.o binary
- Ketchup/Httpd.hi binary
- Ketchup/Httpd.o binary
- Ketchup/Routing.hi binary
- Ketchup/Routing.hs +40/−29
- Ketchup/Routing.o binary
- Ketchup/Static.hi binary
- Ketchup/Static.o binary
- Ketchup/Utils.hi binary
- Ketchup/Utils.hs +9/−3
- Ketchup/Utils.o binary
- example too large to diff
- example.hi binary
- example.hs +6/−6
- example.o binary
@@ -1,1 +1,15 @@-Version bump for cabal+Remove unneded comments+# Please enter the commit message for your changes. Lines starting+# with '#' will be ignored, and an empty message aborts the commit.+# On branch master+# Your branch is up-to-date with 'origin/master'.+#+# Changes to be committed:+# modified: Ketchup/Routing.hs+#+# Untracked files:+# .gitignore~+# Ketchup.cabal~+# example.core+# gendocs.sh~+#
@@ -1,2 +1,2 @@-b83c2375bba608232746064adfdb067cf57e5d80 branch 'master' of github.com:Hamcha/ketchup-4ac44b6241517d43310da25b086e175b3b9c0b49 not-for-merge branch 'gh-pages' of github.com:Hamcha/ketchup+85b4c8d2256c11c570cacf64895353c0b9bd374f branch 'master' of github.com:Hamcha/ketchup+4c2353910734c89633d869f0ffccf8f565c93221 not-for-merge branch 'gh-pages' of github.com:Hamcha/ketchup
@@ -1,1 +1,1 @@-b83c2375bba608232746064adfdb067cf57e5d80+85b4c8d2256c11c570cacf64895353c0b9bd374f
binary file changed (1136 → 1136 bytes)
@@ -26,3 +26,5 @@ 0f03ed98a2eba1beb8db11eb86edb34b2321a261 0fd36c65d057f7ce244a4e9a335d698f075530e6 Hamcha <zikyky@gmail.com> 1404079677 +0200 commit: Version bump 0fd36c65d057f7ce244a4e9a335d698f075530e6 694dea2e0fc5c15b1ef710cee6f953b1afb623bd Hamcha <zikyky@gmail.com> 1404079963 +0200 commit: Promote Auth :D 694dea2e0fc5c15b1ef710cee6f953b1afb623bd 695dee0b1313795711418347aedd65f5bcbca02f Hamcha <zikyky@gmail.com> 1407086956 +0200 commit: Version bump for cabal+695dee0b1313795711418347aedd65f5bcbca02f 83ac9915be5493cf66f1f96de88b5edce6c39929 Hamcha <zikyky@gmail.com> 1407714950 +0200 commit: Doesn't work, but it's a start, will work on it tomorrow+83ac9915be5493cf66f1f96de88b5edce6c39929 85b4c8d2256c11c570cacf64895353c0b9bd374f Hamcha <zikyky@gmail.com> 1407715002 +0200 commit: Remove unneded comments
@@ -26,3 +26,5 @@ 0f03ed98a2eba1beb8db11eb86edb34b2321a261 0fd36c65d057f7ce244a4e9a335d698f075530e6 Hamcha <zikyky@gmail.com> 1404079677 +0200 commit: Version bump 0fd36c65d057f7ce244a4e9a335d698f075530e6 694dea2e0fc5c15b1ef710cee6f953b1afb623bd Hamcha <zikyky@gmail.com> 1404079963 +0200 commit: Promote Auth :D 694dea2e0fc5c15b1ef710cee6f953b1afb623bd 695dee0b1313795711418347aedd65f5bcbca02f Hamcha <zikyky@gmail.com> 1407086956 +0200 commit: Version bump for cabal+695dee0b1313795711418347aedd65f5bcbca02f 83ac9915be5493cf66f1f96de88b5edce6c39929 Hamcha <zikyky@gmail.com> 1407714950 +0200 commit: Doesn't work, but it's a start, will work on it tomorrow+83ac9915be5493cf66f1f96de88b5edce6c39929 85b4c8d2256c11c570cacf64895353c0b9bd374f Hamcha <zikyky@gmail.com> 1407715002 +0200 commit: Remove unneded comments
@@ -1,1 +1,2 @@ 0000000000000000000000000000000000000000 4ac44b6241517d43310da25b086e175b3b9c0b49 Hamcha <zikyky@gmail.com> 1402364070 +0200 pull: storing head+4ac44b6241517d43310da25b086e175b3b9c0b49 4c2353910734c89633d869f0ffccf8f565c93221 Hamcha <zikyky@gmail.com> 1411044679 +0200 pull: fast-forward
@@ -23,3 +23,5 @@ f61d5b2caadecbdcf54d2d0ad7b131ca2adcdc28 0fd36c65d057f7ce244a4e9a335d698f075530e6 Hamcha <zikyky@gmail.com> 1404079685 +0200 update by push 0fd36c65d057f7ce244a4e9a335d698f075530e6 694dea2e0fc5c15b1ef710cee6f953b1afb623bd Hamcha <zikyky@gmail.com> 1404079969 +0200 update by push 694dea2e0fc5c15b1ef710cee6f953b1afb623bd 695dee0b1313795711418347aedd65f5bcbca02f Hamcha <zikyky@gmail.com> 1407086961 +0200 update by push+695dee0b1313795711418347aedd65f5bcbca02f 83ac9915be5493cf66f1f96de88b5edce6c39929 Hamcha <zikyky@gmail.com> 1407714965 +0200 update by push+83ac9915be5493cf66f1f96de88b5edce6c39929 85b4c8d2256c11c570cacf64895353c0b9bd374f Hamcha <zikyky@gmail.com> 1407715015 +0200 update by push
@@ -0,0 +1,4 @@+xßOÛ0Ç÷Ì_aü0à!ñJ 4ÖÄ+L Á@´M×1M¨k{±Óö¿ïl(Ý&M}jz¾ûÜÝ×çI=B½þlûørX|¿:AJtuûñülpBÈ×þãâ};-.ÎQ/})[»Z+& 9ù®3Ïçé¼êfLk²ð¬î>·®Ä4ùS©lþJïðð0{WÁJM cP¥3øÑÖ³µrB¹¤XÿrìÄÂO ^±Æ+ß÷¹ÚIA3ÒýÊZMPÕk.J¹µ5BæØº¥¶Âaä C!:Ç>$`-ojãm84ÃÊRóIÒºZ¦[~d3}¡-¿hÖEÿÃlûnx|TÝmÍkUêyªÔ¬D9zh÷÷v÷ÐOÃÆâì»{_-BîïéÖKUérI³²¡ºÌ±a|Q? ÔÔJÄ%³p'^(>zËT¨dM3¸ #©Óî2lFtæ½V=AdÕûÌG¾¸VÒÌ<eæÌÄÔ¸%¦oÕÈAFp¡î⻢Úê²"µu`]bzΡF`ù¾Dk+]z\£eªÒLS!a¶¤dÆBH+.k>iÐã±7"è¿»Q;{~WÙäôÚèõ+m+=ïô%¼ÊO"wÄä¨uU§ugJ½)³=Ëþ_ÀaÕª(×usì)¼Ðuh°m¼ÖðÔxÒκ9öÆ1Wó5j4n½ Wo×Áö2}¸²øfûõ?hí³4ôªÙå¢D£%zí[1;RÜm éiÜE>7ÆúU±öúéþÊ{"q'Ióø
binary file changed (absent → 874 bytes)
binary file changed (absent → 321 bytes)
binary file changed (absent → 1451 bytes)
binary file changed (absent → 1391 bytes)
binary file changed (absent → 918 bytes)
binary file changed (absent → 161 bytes)
binary file changed (absent → 1159 bytes)
binary file changed (absent → 208 bytes)
@@ -0,0 +1,2 @@+xÎA+1@Q×=Eö$MǶ âÒxT´vëBOï\Áí_[cOiÕçR@%R$ÝJæå2äANg$JÈçÄAÝ$syv`62±Kôeq¢²Õ³75áÀ1x'ï~k3¥êM`÷ïûçp2>6Úê(`À#zX£GtK]Özù¹ÓdÒ5}Aov?¹C$
binary file changed (absent → 1552 bytes)
binary file changed (absent → 1142 bytes)
binary file changed (absent → 603 bytes)
binary file changed (absent → 456 bytes)
@@ -0,0 +1,1 @@+xMjÃ0F»Ö)fEBýE6ÒE½4aË*ò¾"7Èö{¼ÇGµÌ ¬ýà#`N«4çm*iJh6ÒB@-þ|+Ãy´SÝÒR»Ñ:)t·ã4m²ùþηÚà׺yøzæù1?~®ÅçåjùiÐ9iFpD (úÚ¯q|K·õÀ°×6 Ü26ð°±o|=/ËB];®¥¶VwñIQu
@@ -0,0 +1,2 @@+xÍjÃ0{ÖSì=¤Õ%¥Çûëõ§Ä¤²«Ò§¯ó¹Ì0º¶6wbæ·¾TrÈ:fܨ.&¸¦h²+ØoÙ°tÊ^´GÄP¼Öª«%MÈyI})\ÜûuÝè,M¯B§¿ùö¸=>.M毣®í\°ÃࢵLËÖîk/IæmýÝ&zFöÏóíFË
@@ -0,0 +1,3 @@+x]oÓ0¹î¯ð|µ]$^5!QêD*éÐÝF*@Ó.\Ûk¼:vOVÿmPѾïsìsÎJÛÏß¾¡'óÛ,ÿ~w+(5º[~X|Êùz2ÏçèÛU~½@ãøå53N²iB.o0Â@õ¶mãö"¶õä÷dXã`¼rÆNioWjã¿PÆÉ¤7©d"¥¥æ_ U$4jàÌ¢|_Ix¿K0È@"^°ÚIHùÇèF$¥ @ËaÖÊlPQ˧[.¹sÕR'ØÁ^KWH 0;AçNðm°tXÇkUr5÷aBX¾P:~ö¸Wîg¶e½Öô«îè¡'Ù|ÏF2¶±5Ú2ôÔêNÏÐÏåÂMMG<>¦£ ¤ÏâÊ=R"Á¥2Ê?B¨m¿µ¢Ñ2ÒÊ?×ÌùÊpV>N¯»{GIÒF§T«?²»ñ&_.%𢩢YE+áSÀ굯.ò¬A%ÌgB«ÿ"fEc6R£¸W¾«S;ÅQÌ{ëÀ¬¾uÐÅý?í%GQ¾YÝAh§xaÐÄwCOù):ý æ{.
binary file changed (absent → 529 bytes)
binary file changed (absent → 1002 bytes)
binary file changed (absent → 984 bytes)
binary file changed (absent → 1169 bytes)
binary file changed (absent → 727 bytes)
binary file changed (absent → 554 bytes)
binary file changed (absent → 928 bytes)
binary file changed (absent → 207 bytes)
binary file changed (absent → 1028 bytes)
binary file changed (absent → 972 bytes)
binary file changed (absent → 672 bytes)
binary file changed (absent → 321 bytes)
binary file changed (absent → 507 bytes)
binary file changed (absent → 960 bytes)
@@ -1,1 +1,1 @@-695dee0b1313795711418347aedd65f5bcbca02f+85b4c8d2256c11c570cacf64895353c0b9bd374f
@@ -1,1 +1,1 @@-4ac44b6241517d43310da25b086e175b3b9c0b49+4c2353910734c89633d869f0ffccf8f565c93221
@@ -1,1 +1,1 @@-695dee0b1313795711418347aedd65f5bcbca02f+85b4c8d2256c11c570cacf64895353c0b9bd374f
@@ -1,5 +1,5 @@ Name: Ketchup -Version: 0.3.1 +Version: 0.4.0 Cabal-Version: >= 1.6 Build-Type: Simple License: MIT @@ -18,7 +18,7 @@ . * Basic httpd functionality (IPV4 only for now) . - * Regexp routing with parameters (ie. \`/user/:name/(.\*)\`) + * Regexp routing with parameters (ie. \`/user/:name/?\`) . * Static file handler (ie. \`static \".\"\` as route/handler) . @@ -29,8 +29,6 @@ The core parts of Ketchup are all depedency free, that includes Ketchup.Httpd and Ketchup.Utils (and to a certain extent, Ketchup.Chunked). The dependencies required are for the following modules: . - * Ketchup.Routing (uses regex-pcre-builtin, This can ben modified to use builtin POSIX regexp) - . * Ketchup.Static (uses mime-types) . * Ketchup.Auth (uses base64-bytestring) @@ -57,7 +55,6 @@ directory <1.3, mime-types <0.2, network <2.5, - regex-pcre-builtin <1.0, text <2.0 Source-Repository head
binary file changed (2110 → absent bytes)
binary file changed (26408 → absent bytes)
binary file changed (7619 → absent bytes)
binary file changed (28672 → absent bytes)
binary file changed (4273 → absent bytes)
binary file changed (42152 → absent bytes)
binary file changed (3472 → absent bytes)
@@ -2,6 +2,8 @@ module Ketchup.Routing ( Route (..) +, match +, prefix , route , useHandler ) where @@ -10,47 +12,56 @@ import Ketchup.Httpd import Ketchup.Utils import Network -import qualified Text.Regex.PCRE as R -type Route = Socket -> HTTPRequest -> (B.ByteString -> Maybe B.ByteString) -> IO () - +type Route = Socket -> HTTPRequest -> (B.ByteString -> Maybe B.ByteString) -> IO () +type Matcher = B.ByteString -> (Bool, Arguments) +data Arguments = None | Parameters [(B.ByteString, B.ByteString)] + deriving Show -- |Router function -- Takes a list of routes and iterates through them for every requeust -route :: [(B.ByteString, Route)] -- ^ Routes +route :: [(Matcher, Route)] -- ^ Routes -> Handler route [] handle request = sendNotFound handle route (r:routes) handle request - | match (uri request) (fst r) = (snd r) handle request $ - params (uri request) (fst r) - | otherwise = route routes handle request + | isMatch = (snd r) handle request (get params) + | otherwise = route routes handle request + where + isMatch = fst matched + params = snd matched + matched = (fst r) (uri request) + -- |Wrap a handler in a route -- Lets you use a handler (no parameters) as a route useHandler :: Handler -> Route useHandler handler hnd req params = handler hnd req -match :: B.ByteString -> B.ByteString -> Bool -match url template = - and $ zipWith compare urlparts tmpparts +match :: B.ByteString -> Matcher +match template url = + (isMatch, Parameters params) where - compare x y - | x == y = True - | or [B.null y, B.null x] = False - | B.head y == ':' = True - | x R.=~ y = True - | otherwise = False + isMatch = fst parsed + params = snd parsed + parsed = parse urlparts temparts [] urlparts = B.split '/' url - tmpparts = B.split '/' template + temparts = B.split '/' template -params :: B.ByteString -> B.ByteString -> B.ByteString -> Maybe B.ByteString -params url template name = - lookup name list - where - list = filter (not . B.null . fst) $ - zipWith retrieve urlparts tmpparts - retrieve x y - | or [B.null y, B.null x] = ("","") - | B.head y == ':' = (B.tail y, x) - | otherwise = ("","") - urlparts = B.split '/' url - tmpparts = B.split '/' template+parse :: [B.ByteString] + -> [B.ByteString] + -> [(B.ByteString, B.ByteString)] + -> (Bool, [(B.ByteString, B.ByteString)]) +parse [] [] params = (True, params) +parse (u:url) [] params = (False, []) +parse [] (t:temp) params = (False, []) +parse (u:url) (t:temp) params + | B.length t < 1 = parse url temp params + | B.head t == ':' = parse url temp ((B.tail t, u) : params) + | u == t = parse url temp params + | otherwise = (False, []) + +prefix :: B.ByteString -> Matcher +prefix urlPrefix url = (B.isPrefixOf urlPrefix url, None) + +get :: Arguments -> B.ByteString -> Maybe B.ByteString +get (Parameters params) x = lookup x params +get None x = Nothing
binary file changed (30512 → absent bytes)
binary file changed (2100 → absent bytes)
binary file changed (15600 → absent bytes)
binary file changed (18874 → absent bytes)
@@ -1,14 +1,15 @@ {-# LANGUAGE OverloadedStrings #-} module Ketchup.Utils -( trim -, breakBS +( breakBS , fallback , parseBody -, sendReply , sendBadRequest , sendNotFound +, sendReply , statusMsg +, subBS +, trim ) where import qualified Data.ByteString.Char8 as B @@ -87,10 +88,15 @@ second = B.drop (B.length delimiter) $ snd broke broke = B.breakSubstring delimiter source +-- |Get a substring of a ByteString +subBS :: Int -> Int -> B.ByteString -> B.ByteString +subBS start length = B.take length . B.drop start + -- |Parse a URL-encoded Request parseBody :: B.ByteString -> [(B.ByteString, B.ByteString)] parseBody body = map (breakBS "=") $ B.split '&' body +-- |Maybe a -> a with fallback (if Nothing) fallback :: Maybe a -> a -> a fallback (Just value) fallback = value fallback Nothing fallback = fallback
binary file changed (79464 → absent bytes)
file too large to diff
binary file changed (23780 → absent bytes)
@@ -32,12 +32,12 @@ print $ parseBody $ body req sendReply hnd 200 [("Content-Type", ["text/html"])] "OK!" -router = route [ ("/" , useHandler $ handle ) - , ("/greet/:user" , greet ) - , ("/chunk" , useHandler $ chunked ) - , ("/post" , useHandler $ post ) - , ("/Ketchup/(.*)", useHandler $ static "." ) - , ("/auth" , useHandler $ basicAuth [("a","b")] "test" handle ) +router = route [ (match "/greet/:user" , greet ) + , (prefix "/chunk/" , useHandler $ chunked ) + , (match "/post" , useHandler $ post ) + , (prefix "/Ketchup/" , useHandler $ static "." ) + , (match "/auth" , useHandler $ basicAuth [("a","b")] "test" handle ) + , (match "/" , useHandler $ handle ) ] main = do listenHTTP "*" 8080 router
binary file changed (76544 → absent bytes)