git.fiddlerwoaroof.com
Browse code

increment

Ed Langley authored on 29/10/2020 22:35:09
Showing 2 changed files
... ...
@@ -4,9 +4,11 @@
4 4
   :description "Describe http-streams here"
5 5
   :author "Your Name <your.name@example.com>"
6 6
   :license "Specify license here"
7
-  :depends-on (#:fwoar.lisputils
7
+  :depends-on (#:fwoar-lisputils
8 8
                #:alexandria
9
-               #:serapeum)
9
+               #:serapeum
10
+	             #:cl+ssl
11
+	             #:usocket)
10 12
   :serial t
11 13
   :components ((:file "package")
12 14
                (:file "http-streams")))
... ...
@@ -17,6 +17,20 @@
17 17
   `(prog1 ,form
18 18
      (end-line ,stream)))
19 19
 
20
+(defun lookup-status (status)
21
+  (ecase status
22
+    (200 "OK")
23
+    (400 "Bad Request")
24
+    (404 "Not Found")
25
+    (301 "Moved Permanently")
26
+    (302 "Moved Temporarily")
27
+    ))
28
+
29
+(defun response (status out-stream)
30
+  (with-line (out-stream)
31
+    (format out-stream "HTTP/1.1 ~d ~a" status (lookup-status status)))
32
+  out-stream)
33
+
20 34
 (defun request (method path out-stream)
21 35
   (with-line (out-stream)
22 36
     (format out-stream "~a ~a HTTP/1.1" method path))
... ...
@@ -117,38 +131,3 @@
117 131
 	      headers
118 132
 	      content-length))))
119 133
 
120
-
121
-#|
122
-(defun get-subreddit-feed ()
123
-  (usocket:with-client-socket (so st "reddit.com" 443 :element-type '(unsigned-byte 8))
124
-    (let* ((ssl-stream (cl+ssl:make-ssl-client-stream st :hostname "reddit.com"))
125
-	   (char-stream (flexi-streams:make-flexi-stream ssl-stream :external-format :iso-8859-1)))
126
-      (unwind-protect (locally (declare (optimize (debug 3)))
127
-			(progn (build-subreddit-request :GET "lisp" char-stream)
128
-			       (finish-output char-stream)
129
-			       (multiple-value-bind (result headers) (read-in-header char-stream)
130
-				 (let ((reply-buf (make-string (parse-integer (cadr (assoc "Content-Length" headers
131
-											   :test 'equalp))))))
132
-				   (values reply-buf
133
-					   result
134
-					   headers
135
-					   (read-sequence reply-buf char-stream))))))
136
-	(close ssl-stream)))))
137
-
138
-(defparameter *old-readtable* (copy-readtable *readtable*))
139
-(set-macro-character #\] 'identity nil)
140
-(set-dispatch-macro-character
141
- #\# #\[
142
- (lambda (s c n)
143
-   (let ((list (read-delimited-list #\] s t)))
144
-     (fw.lu:rollup-list
145
-      (loop with result = ()
146
-	 for (arg op) on list by #'cddr
147
-	 while op
148
-	 do
149
-	   (push `(,op ,arg)
150
-		 result)
151
-	 finally
152
-	   (push arg result)
153
-	   (return (nreverse result)))))))
154
-|#