Skip to content

Commit

Permalink
Make a simple definition of package on cap13-webserver
Browse files Browse the repository at this point in the history
To avoid problems with :usocket on emacs, use load :usocket before defpackage
and :shadow :usocket symbol to avoid conflicts.
  • Loading branch information
ryukinix committed Mar 17, 2017
1 parent 873f529 commit bb4ebc4
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions land-of-lisp/cap13-webserver.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
;; NOTE: this web server is adapted from 'http.lisp' created by Ron Garret.

;; Decoding the Values of Request Parameters
(ql:quickload 'usocket)

(defpackage :webserver
(:use :cl :usocket)
(:export :serve)
(:shadow :usocket))

(in-package :webserver)

(defun http-char (c1 c2 &optional (default #\Space))
(let ((code (parse-integer
Expand Down Expand Up @@ -104,8 +112,6 @@ bar: abc, 123
(read-sequence content stream)
(parse-params content)))))

(ql:quickload 'usocket)
(use-package 'usocket)

;; The server function is briefly modified to working with SBCL and USOCKET

Expand Down Expand Up @@ -138,14 +144,14 @@ bar: abc, 123
(format t "<html>Nice to meet you, ~a!</html>" (cdr name))))
(princ "ERROR 404 - Sorry... I don't know that page")))

(hello-request-handler "lolcats" '() '())
;; (hello-request-handler "lolcats" '() '())
;; => ERROR 404 - Sorry... I don't know that page

(hello-request-handler "greeting" '() ())
;; (hello-request-handler "greeting" '() ())
;; => <html><form>What is your name?<input name='name'/></form></html>

;; Executing the server...
(serve #'hello-request-handler)
;; (serve #'hello-request-handler)
;; You can access this server on
;; 127.0.0.1:8080/greeting

Expand Down

0 comments on commit bb4ebc4

Please sign in to comment.