Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

url mapping is almost done, except static file and folders.

  • Loading branch information...
commit df4920d20d081aa12f11ddd0be857e4b082afdb7 1 parent 401ce29
asdr the admin authored
View
4 easyweb.asd
@@ -10,7 +10,9 @@
:serial t
:depends-on (#:dsgner #:hunchentoot)
:components ((:file "util")
+ (:file "url-handler")
(:file "easyweb")
- (:file "html")))
+ (:file "html")
+ (:file "initialize")))
View
3  easyweb.lisp
@@ -40,7 +40,7 @@
(destructuring-bind (none0 arguments &rest rest)
(get-lambda-list handler)
(let ((args (cdr rest))) ;;because the first of rest is &key
- `(define-easy-handler (,(gensym) :uri ,uri-content)
+ `(define-url-handler (,(gensym) :uri ,(cons uri-type uri-content))
,(mapcar #'(lambda(arg)
(if (listp arg)
(car arg)
@@ -65,7 +65,6 @@
(stop *httpd*)
(setf *httpd* nil))
-
(defmacro defview (name inner-args (&rest arguments) &body body)
`(progn
(defun ,name (&rest ,inner-args ,@(let ((ret (mapcar #'(lambda(arg)
View
5 initialize.lisp
@@ -0,0 +1,5 @@
+;;here are the initilization of easyweb environment
+(in-package :easyweb)
+
+;;set our new dispatcher to hunchentoot
+(setf hunchentoot:*dispatch-table* (list #'hunchentoot:dispatch-url-handlers))
View
6 prototype-app1/_settings.lisp
@@ -10,10 +10,10 @@
;;URLs
(map-all-urls "/"
- ((:std "") index-page)
+ ((:prefix "") index-page)
; ((:std "asdr") open-link)
- ((:std "argtest") argtest))
-; ((:prefix "serdar") mervecigim)
+ ((:absolute "argtest") argtest)
+ ((:regex "asdr[0-9]+$") mervecigim))
; ((:std "merve") mervecigim))
; ((:file "tmp/fileX" "/home/admin-o/pjs/easyweb/tmp/filex.x" "text/plain"))
; ((:folder "tmp/" "/home/asdr/admin-o/pjs/easyweb/" "text/plain")))
View
56 url-handler.lisp
@@ -0,0 +1,56 @@
+#|
+This code is almost taken from hunchentoot source code.
+Briefly, the work done in here is defining new easy-handler and a dispatcher for le-jango.
+In hanchentoot define-easy-handler macro just works for absolute uris, however I need the
+other handling types, e.g. regex and prefix matching, which can also be found in hunchentoot,
+but not in define-easy-handler macro. So below is that for...
+
+--asdr
+|#
+
+(in-package :hunchentoot)
+
+(defparameter *url-handlers* nil
+ "Handlers are stored in this list.")
+
+(defun dispatch-url-handlers (request)
+ (loop for ((uri-type . uri-content) acceptor-names easy-handler) in *url-handlers*
+ when (and (or (eq acceptor-names t)
+ (find (acceptor-name *acceptor*) acceptor-names :test #'eq))
+ (cond ((stringp uri-content)
+ (case uri-type
+ (:absolute ;;ABOLUTE matching
+ (string= uri-content (script-name request)))
+ (:prefix ;;PREFIX matching
+ (let ((mismatch (mismatch (script-name request) uri-content
+ :test #'char=)))
+ (and (or (null mismatch)
+ (>= mismatch (length uri-content))))))
+ (:regex ;;Regular EXP. matching
+ (let ((scanner (create-scanner uri-content)))
+ (not (null (scan scanner (script-name request))))))))
+ (t (funcall uri-content request))))
+ do (return easy-handler)))
+
+(defmacro define-url-handler (description lambda-list &body body)
+ (when (atom description)
+ (setq description (list description)))
+ (destructuring-bind (name &key uri (acceptor-names t)
+ (default-parameter-type ''string)
+ (default-request-type :both))
+ description
+ `(progn
+ (setq *url-handlers* (delete-if #'(lambda (list)
+ (or (equal ,(cdr uri) (cdr (first list)))
+ (eq ',name (third list))))
+ *url-handlers*))
+ (push (list ',uri ,acceptor-names ',name) *url-handlers*)
+
+ (defun ,name (&key ,@(loop for part in lambda-list
+ collect (make-defun-parameter part
+ default-parameter-type
+ default-request-type)))
+ ,@body))))
+
+(export 'dispatch-url-handlers)
+(export 'define-url-handler)
Please sign in to comment.
Something went wrong with that request. Please try again.