Commits

Richo Healey committed 758258f

Try to create an abstract request type

Comments (0)

Files changed (2)

 (define get-request-method
+  (lambda (req)
+    (cdr (assoc 'method req))))
+
+(define request-method-from-line
   (lambda (line)
     (car (string-tokenize line))))
 
 (define get-request-path
+  (lambda (req)
+    (cadr (assoc 'path req))))
+(define request-path-from-line
   ; Maximum ghetto. Expect a line like:
   ; GET /index.html HTTP/1.1
   (lambda (line)
       ; TODO strip query strings
       (car (cdr tokenized-line)))))
 
+(define make-request
+  (lambda (line) ; port?
+    '((path (get-request-path line))
+      (method (get-request-method line)))))
     ; about from it's first line
     (let ((line (read-line in)))
       (if (not (equal? line #!eof))
-        (let ((request-path (get-request-path line))
-           (request-method (get-request-method line))
-           (response (make-response)))
+        (let* ((request (make-request line))
+               (response (make-response))
+               (request-path (get-request-path request)))
       (write-response
         (cond ((string=? request-path "/")
              (set-response-header "Content-Type" "text/html"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.