Permalink
Browse files

add matched-part count to elnode-http-mapping

  • Loading branch information...
1 parent a4b7626 commit d77f3f1551db9d0283b188a6a8fb56e6bb7c65f0 @nicferrier committed Mar 27, 2013
Showing with 14 additions and 5 deletions.
  1. +5 −0 elnode-tests.el
  2. +9 −5 elnode.el
View
@@ -935,12 +935,17 @@ Content-Type: text/html\r
'(("[^/]+//wiki/\\(.*\\)" . elnode-wikiserver)
("[^/]+//.*" . elnode-webserver)))
'elnode-wikiserver))
+ (should (equal (elnode-http-mapping :httpcon t) 2))
(should
(equal
(elnode-http-mapping :httpcon)
"localhost//wiki/somefile.creole"))
(should
(equal
+ (elnode-http-mapping :httpcon 0)
+ "localhost//wiki/somefile.creole"))
+ (should
+ (equal
(elnode-http-mapping :httpcon 1)
"somefile.creole"))
(should
View
@@ -2041,8 +2041,9 @@ inside your handler with `elnode-http-mapping'."
(defun elnode-http-mapping (httpcon &optional part)
"Return the match on the HTTPCON that resulted in the current handler.
-With PART it returns a specific part of the match , by default
-PART is 0.
+With PART it returns a specific part of the match, by default
+PART is 0. If PART is specified as `t' then the count of parts
+is returned.
This results only from a call via `elnode-dispatcher'.
@@ -2062,9 +2063,12 @@ The following is true inside the handler:
The function `elnode-test-path' uses this facility to work out a
target path."
- (elt
- (process-get httpcon :elnode-http-mapping)
- (if part part 0)))
+ (if (eq part t)
+ (length (process-get httpcon :elnode-http-mapping))
+ ;; Else it's a specific part
+ (elt
+ (process-get httpcon :elnode-http-mapping)
+ (if part part 0))))
(defun elnode--strip-leading-slash (str)
"Strip any leading slash from STR.

0 comments on commit d77f3f1

Please sign in to comment.