We don't actually expect anyone to use this backend but 1) it's convenient when getting starting and 2) the mod_lisp backend reuses most of it.
(eval-when (:compile-toplevel :load-toplevel :execute) (defclass httpd-backend (backend) ((port :accessor port :initarg :port :initform 8080) (host :accessor host :initarg :host :initform "127.0.0.1") (socket :accessor socket) (server :accessor server :initarg :server) (handlers :accessor handlers :initform '()))) (defclass httpd-message (message) ((headers :accessor headers :initform '()) (network-stream :accessor network-stream :initarg :network-stream))) (defclass httpd-request (httpd-message request) ((parameters :accessor parameters :initform '()) (raw-uri :accessor raw-uri) (query-path :accessor query-path) (raw-body :accessor raw-body :initform nil) (http-method :accessor http-method :initform nil))) (defclass httpd-response (httpd-message response) ((content-stream :accessor content-stream :initform (make-string-output-stream)) (status :accessor status :initform "200 OK"))))
Backend methods
Method (SEND-ERROR STREAM T) Ignore trying to read the request or anything.
The single threaded server
Method (STARTUP-BACKEND HTTPD-BACKEND) Start the RERL.
Method (SHUTDOWN-BACKEND HTTPD-BACKEND) This would stop the single therad httpd backend if that made any sense.
Function MAP-QUERY-PATH-TO-FILE Converts QUERY-PATH to a file on the local filesystem assuming the application is mapped to URL-BASE and lives in DIRECTORY.
Message headers methods
Request handling
Method (READ-LINE-FROM-NETWORK HTTPD-BACKEND T) A simple state machine which reads chars from STREAM until it gets a CR-LF sequence or the end of the stream.
Method (READ-REQUEST HTTPD-BACKEND T) Reads an HTTP request message from STREAM.
helpers for parsing incoming http requests
Function SPLIT-ON-SPACE Split line on #Space.
Response objects
httpd-response objects special case the "Status" header.
Debugging the backend