Skip to content

Commit

Permalink
Clean clack-handler-fcgi up.
Browse files Browse the repository at this point in the history
  • Loading branch information
fukamachi committed Mar 26, 2015
1 parent 0e37159 commit eb2aa07
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 97 deletions.
7 changes: 1 addition & 6 deletions clack-handler-fcgi.asd
Expand Up @@ -21,14 +21,9 @@
:version "0.3.1" :version "0.3.1"
:author "Eitaro Fukamachi" :author "Eitaro Fukamachi"
:license "LLGPL" :license "LLGPL"
:depends-on (:clack :depends-on (:cl-fastcgi
:cl-syntax
:cl-syntax-annot
:cl-fastcgi
:alexandria :alexandria
:flexi-streams :flexi-streams
:cl-ppcre
:split-sequence
:usocket :usocket
:quri) :quri)
:components ((:file "src/handler/fcgi")) :components ((:file "src/handler/fcgi"))
Expand Down
1 change: 0 additions & 1 deletion clack.asd
Expand Up @@ -29,7 +29,6 @@
:components :components
((:file "clack" :depends-on ("handler")) ((:file "clack" :depends-on ("handler"))
(:file "handler" :depends-on ("util")) (:file "handler" :depends-on ("util"))
(:file "http-status")
(:file "util")))) (:file "util"))))
:description "Web application environment for Common Lisp" :description "Web application environment for Common Lisp"
:long-description :long-description
Expand Down
83 changes: 57 additions & 26 deletions src/handler/fcgi.lisp
@@ -1,38 +1,23 @@
#|
This file is a part of Clack package.
URL: http://github.com/fukamachi/clack
Copyright (c) 2011 Eitaro Fukamachi <e.arrows@gmail.com>
Clack is freely distributable under the LLGPL License.
|#

(in-package :cl-user) (in-package :cl-user)
(defpackage clack.handler.fcgi (defpackage clack.handler.fcgi
(:use :cl (:use :cl
:cl-fastcgi) :cl-fastcgi)
(:import-from :clack.http-status
:http-status-reason)
(:import-from :quri (:import-from :quri
:url-decode) :url-decode
(:import-from :alexandria :uri-malformed-string)
:make-keyword
:when-let)
(:import-from :flexi-streams (:import-from :flexi-streams
:make-flexi-stream
:make-in-memory-input-stream :make-in-memory-input-stream
:string-to-octets) :string-to-octets)
(:import-from :cl-ppcre
:regex-replace-all)
(:import-from :usocket (:import-from :usocket
:stream-server-usocket :stream-server-usocket
:socket-listen :socket-listen
:socket-close) :socket-close)
(:import-from :split-sequence (:import-from :alexandria
:split-sequence)) :make-keyword
:when-let)
(:export :run))
(in-package :clack.handler.fcgi) (in-package :clack.handler.fcgi)


(cl-syntax:use-syntax :annot)

(defclass <fcgi-acceptor> () (defclass <fcgi-acceptor> ()
((port :type integer ((port :type integer
:initarg :port :initarg :port
Expand All @@ -58,7 +43,6 @@
(setf (acceptor-file-descriptor acceptor) (setf (acceptor-file-descriptor acceptor)
(cl-fastcgi::usocket-to-fd socket))))) (cl-fastcgi::usocket-to-fd socket)))))


@export
(defun run (app &key (debug t) (port 9000) fd) (defun run (app &key (debug t) (port 9000) fd)
"Start FastCGI server." "Start FastCGI server."
(flet ((main-loop (req) (flet ((main-loop (req)
Expand All @@ -83,7 +67,6 @@
(stop acceptor)) (stop acceptor))
acceptor))) acceptor)))


@export
(defun stop (acceptor) (defun stop (acceptor)
(when-let (socket (acceptor-socket acceptor)) (when-let (socket (acceptor-socket acceptor))
(usocket:socket-close socket))) (usocket:socket-close socket)))
Expand Down Expand Up @@ -217,7 +200,55 @@ before passing to Clack application."
do (vector-push val buf)) do (vector-push val buf))
finally finally
(return (return
(flex:make-flexi-stream (flex:make-in-memory-input-stream buf)))
(flex:make-in-memory-input-stream buf)
:external-format :utf-8)))
:clack.streaming t))))))) :clack.streaming t)))))))

(defvar *http-status* (make-hash-table :test #'eql))

(macrolet ((def-http-status (code phrase)
`(setf (gethash ,code *http-status*) ,phrase)))
(def-http-status 100 "Continue")
(def-http-status 101 "Switching Protocols")
(def-http-status 200 "OK")
(def-http-status 201 "Created")
(def-http-status 202 "Accepted")
(def-http-status 203 "Non-Authoritative Information")
(def-http-status 204 "No Content")
(def-http-status 205 "Reset Content")
(def-http-status 206 "Partial Content")
(def-http-status 207 "Multi-Status")
(def-http-status 300 "Multiple Choices")
(def-http-status 301 "Moved Permanently")
(def-http-status 302 "Moved Temporarily")
(def-http-status 303 "See Other")
(def-http-status 304 "Not Modified")
(def-http-status 305 "Use Proxy")
(def-http-status 307 "Temporary Redirect")
(def-http-status 400 "Bad Request")
(def-http-status 401 "Authorization Required")
(def-http-status 402 "Payment Required")
(def-http-status 403 "Forbidden")
(def-http-status 404 "Not Found")
(def-http-status 405 "Method Not Allowed")
(def-http-status 406 "Not Acceptable")
(def-http-status 407 "Proxy Authentication Required")
(def-http-status 408 "Request Time-out")
(def-http-status 409 "Conflict")
(def-http-status 410 "Gone")
(def-http-status 411 "Length Required")
(def-http-status 412 "Precondition Failed")
(def-http-status 413 "Request Entity Too Large")
(def-http-status 414 "Request-URI Too Large")
(def-http-status 415 "Unsupported Media Type")
(def-http-status 416 "Requested range not satisfiable")
(def-http-status 417 "Expectation Failed")
(def-http-status 424 "Failed Dependency")
(def-http-status 500 "Internal Server Error")
(def-http-status 501 "Not Implemented")
(def-http-status 502 "Bad Gateway")
(def-http-status 503 "Service Unavailable")
(def-http-status 504 "Gateway Time-out")
(def-http-status 505 "Version not supported"))

(defun http-status-reason (code)
(gethash code *http-status*))
64 changes: 0 additions & 64 deletions src/http-status.lisp

This file was deleted.

0 comments on commit eb2aa07

Please sign in to comment.