Fixing same-servlet to support arbitrary junk after servlet file

svn: r6360
This commit is contained in:
Jay McCarthy 2007-05-28 18:24:42 +00:00
parent 9b494f9d1b
commit 7b1a5db1df
3 changed files with 44 additions and 32 deletions

View File

@ -122,14 +122,26 @@
(request-method req)))))) (request-method req))))))
; same-servlet? : url? url? -> boolean? ; same-servlet? : url? url? -> boolean?
(define (same-servlet? u v) (define (same-servlet? req ses)
(define (abstract-url u) (define (abstract-url u)
(path->string (map path/param-path
(apply build-path (url-path u)))
(map path/param-path (define ans
(url-path u))))) (let loop ([rp (abstract-url req)]
(string=? (abstract-url u) [sp (abstract-url ses)])
(abstract-url v))) (match sp
[(list)
#t]
[(list-rest s sp)
(match rp
[(list)
#f]
[(list-rest r rp)
(if (string=? s r)
(loop rp sp)
#f)])])))
(myprint "~S => ~S~n" `(same-servlet? ,(url->string req) ,(url->string ses)) ans)
ans)
;; resume-session: number connection request ;; resume-session: number connection request
(define (resume-session ses-id conn req) (define (resume-session ses-id conn req)
@ -137,8 +149,7 @@
(cond (cond
[(lookup-session ses-id) [(lookup-session ses-id)
=> (lambda (ses) => (lambda (ses)
(if (same-servlet? (request-uri req) (if (same-servlet? (request-uri req) (session-url ses))
(session-url ses))
(parameterize ([current-custodian (session-cust ses)] (parameterize ([current-custodian (session-cust ses)]
[current-session ses]) [current-session ses])
(with-handlers ([void (with-handlers ([void
@ -147,7 +158,7 @@
conn conn
(responders-servlet (request-uri req) the-exn) (responders-servlet (request-uri req) the-exn)
(request-method req)))]) (request-method req)))])
#;(printf "session-handler ~S~n" (session-handler ses)) (myprint "session-handler ~S~n" (session-handler ses))
(output-response conn (output-response conn
((session-handler ses) req)))) ((session-handler ses) req))))
(begin-session conn req)))] (begin-session conn req)))]

View File

@ -1,5 +1,6 @@
(module utils mzscheme (module utils mzscheme
(require (lib "url.ss" "net") (require (lib "url.ss" "net")
(lib "plt-match.ss")
(lib "list.ss")) (lib "list.ss"))
(provide url->servlet-path (provide url->servlet-path
make-session-url make-session-url
@ -82,20 +83,20 @@
[servlet-path '()] [servlet-path '()]
[path-list (simplify-url-path uri)]) [path-list (simplify-url-path uri)])
#;(printf "~S~n" `(loop ,base-path ,servlet-path ,path-list)) #;(printf "~S~n" `(loop ,base-path ,servlet-path ,path-list))
(if (match path-list
(null? path-list) [(list)
(values #f #f #f) (values #f #f #f)]
(let* ([next-path-segment (car path-list)] [(list-rest next-path-segment rest-of-path)
[new-base (build-path base-path next-path-segment)]) (let ([new-base (build-path base-path next-path-segment)])
#;(printf " new-base = ~s~n" new-base) #;(printf " new-base = ~s~n" new-base)
(cond (cond
[(file-exists? new-base) [(file-exists? new-base)
(values new-base (values new-base
(reverse (cons next-path-segment servlet-path)) (reverse (list* next-path-segment servlet-path))
(cdr path-list))] rest-of-path)]
[else (loop new-base [else (loop new-base
(cons next-path-segment servlet-path) (list* next-path-segment servlet-path)
(cdr path-list))]))))) rest-of-path)]))])))
;; split-url-path: url url -> (union (listof string) #f) ;; split-url-path: url url -> (union (listof string) #f)
;; the first url's path is a prefix of the path of the second ;; the first url's path is a prefix of the path of the second

View File

@ -59,7 +59,7 @@
(define dispatch (define dispatch
(sequencer:make (sequencer:make
(filter:make (filter:make
#rx"\\.ss$" #rx"\\.ss"
(servlets2:make #:htdocs-path htdocs-path (servlets2:make #:htdocs-path htdocs-path
#:timeouts-servlet-connection 86400 #:timeouts-servlet-connection 86400
#:responders-servlet-loading responders-servlet-loading #:responders-servlet-loading responders-servlet-loading