[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 03/119: parsing HTTP headers
From: |
Eric Schulte |
Subject: |
[elpa] 03/119: parsing HTTP headers |
Date: |
Mon, 10 Mar 2014 16:56:37 +0000 |
eschulte pushed a commit to branch master
in repository elpa.
commit cc598c436b1e4b753771dd073f958275691bdee1
Author: Eric Schulte <address@hidden>
Date: Tue Dec 17 23:16:55 2013 -0700
parsing HTTP headers
---
emacs-web-server.el | 34 +++++++++++++++++++++++-----------
1 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/emacs-web-server.el b/emacs-web-server.el
index 162eb8b..8c1ec6b 100644
--- a/emacs-web-server.el
+++ b/emacs-web-server.el
@@ -54,19 +54,31 @@ URI and any post data."
(mapc #'delete-process (append (mapcar #'car (clients server))
(list (process server)))))
-(defun ews-filter (proc string)
+(defun ews-parse (string)
+ (cond
+ ((string-match "^GET \\([^[:space:]]+\\) \\([^[:space:]]+\\)$" string)
+ (list (cons :GET (match-string 1 string))
+ (cons :TYPE (match-string 2 string))))
+ ((string-match "^\\([^[:space:]]+\\): \\(.*\\)$" string)
+ (list (cons (intern (concat ":" (upcase (match-string 1 string))))
+ (match-string 2 string))))
+ (:otherwise (message "[ews] bad header: %S" string) nil)))
+
+(defun ews-filter (proc string)
(with-slots (handler clients) (plist-get (process-plist proc) :server)
;; register new client
- (unless (assoc proc clients) (push (cons proc "") clients))
- (let* ((pending (assoc proc clients))
- (message (concat (cdr pending) string))
- index)
- ;; read whole strings
- (while (setq index (string-match "\n" message))
- (setq index (1+ index))
- (process-send-string proc (substring message 0 index))
- (setq message (substring message index)))
- (setcdr pending message))))
+ (unless (assoc proc clients) (push (list proc "") clients))
+ (let* ((client (assoc proc clients)) ; clients are (proc pending headers)
+ (pending (concat (cadr client) string))
+ (last-index 0) index)
+ ;; parse headers and append to client
+ (while (setq index (string-match "\r\n" pending last-index))
+ ;; double newline indicates no more headers
+ (unless (= last-index index)
+ (setcdr (last client)
+ (ews-parse (substring pending last-index index))))
+ (setq last-index (+ index 2)))
+ (setcar (cdr client) (substring pending last-index)))))
(provide 'emacs-web-server)
;;; emacs-web-server.el ends here
- [elpa] branch master updated (f64a801 -> 4f28097), Eric Schulte, 2014/03/10
- [elpa] 02/119: logging support, Eric Schulte, 2014/03/10
- [elpa] 03/119: parsing HTTP headers,
Eric Schulte <=
- [elpa] 01/119: initial commit, echo server working, Eric Schulte, 2014/03/10
- [elpa] 04/119: simple hello world server working, Eric Schulte, 2014/03/10
- [elpa] 05/119: stub out (but don't write any) tests, Eric Schulte, 2014/03/10
- [elpa] 08/119: NOTES file for tasks and notes, Eric Schulte, 2014/03/10
- [elpa] 07/119: TODO: handle post data, Eric Schulte, 2014/03/10
- [elpa] 06/119: helper for HTTP headers, Eric Schulte, 2014/03/10
- [elpa] 09/119: parsing form data in POST, Eric Schulte, 2014/03/10
- [elpa] 11/119: more flexible network process creation, Eric Schulte, 2014/03/10
- [elpa] 10/119: some simple examples, Eric Schulte, 2014/03/10
- [elpa] 15/119: more lenient parsing of multipart forms, Eric Schulte, 2014/03/10