;; examples/servlets.scm -- module with user servlets for the webserver
;;
;; Copyright (C) 2000 Martin Grabmueller <mgrabmue@cs.tu-berlin.de>
;;
;; This is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; 
;; This software is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;; 
;; You should have received a copy of the GNU General Public License
;; along with this package; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.  

;; This procedure demonstrates how you can write your own customized
;; servlet in SizzWeb.
;;
;; A servlet procedure must perform the followin steps.
;; - Send an HTTP response line (with send-success for example)
;; - Send appropriate headers (with send-standard-header or send-header)
;; - Send the content (with send-contents, which takes a list of strings)
;; - Commit the response with send-reply.

(define (user-servlet-handler in-port out-port method url headers)
  (send-success)
  (send-standard-header)
  (send-header "Connection" "close")
  (send-header "Content-Type" "text/html")
  (send-content
   (append '(
"<html>
<head>
<title>User servlet</title>
</head>
<body>
<h2>User servlet</h2>
<p>
This is the servlet from the Sizzle distribution talking.
</p>
</body>
</html>
")))
  (send-reply out-port))

;; Register the user servlet to respond for all URLs below `/user'.
(add-dynamic-handler! "/user" user-servlet-handler)
;; Uncomment the following if you want to install the example servlet
;; as the root page.
;(add-dynamic-handler! "/" user-servlet-handler)
