#lang scheme/base
(require web-server/configuration/namespace
(prefix-in file: web-server/dispatchers/dispatch-files)
(prefix-in sequencer: web-server/dispatchers/dispatch-sequencer)
(prefix-in servlet: web-server/dispatchers/dispatch-servlets)
(prefix-in lang: web-server/dispatchers/dispatch-lang)
web-server/dispatchers/filesystem-map
web-server/private/cache-table
web-server/private/mime-types)
(define (make-instaweb-dispatcher
#:app-dispatcher dispatch-application
#:htdocs-path htdocs-path
#:mime-types-path mime-types-path)
(define (htdocs-url->path path)
(make-url->path (path->complete-path path)))
(define dispatch-htdocs
(apply sequencer:make
(map (lambda (path)
(file:make #:url->path (htdocs-url->path path)
#:path->mime-type (make-path->mime-type (path->complete-path mime-types-path))))
htdocs-path)))
(sequencer:make dispatch-htdocs dispatch-application))
(define (make-application-dispatcher
#:servlet-lang servlet-lang
#:servlet-path servlet-path
#:servlet-namespace servlet-namespace)
(define (servlet-url->path url)
(let ([complete-servlet-path (path->complete-path servlet-path)])
(values complete-servlet-path null)))
(if (eq? servlet-lang 'web-server)
(let ([make-servlet-namespace (make-make-servlet-namespace #:to-be-copied-module-specs servlet-namespace)])
(lang:make #:url->path servlet-url->path
#:make-servlet-namespace make-servlet-namespace))
(let ([make-servlet-namespace (make-make-servlet-namespace #:to-be-copied-module-specs servlet-namespace)])
(let-values ([(clear-table! dispatcher)
(servlet:make (box (make-cache-table))
#:url->path servlet-url->path
#:make-servlet-namespace make-servlet-namespace)])
dispatcher))))
(provide make-instaweb-dispatcher
make-application-dispatcher)