emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 07/119: TODO: handle post data


From: Eric Schulte
Subject: [elpa] 07/119: TODO: handle post data
Date: Mon, 10 Mar 2014 16:56:58 +0000

eschulte pushed a commit to branch master
in repository elpa.

commit 9b1b31221f1a4f3aec1038a2033c06858ad80172
Author: Eric Schulte <address@hidden>
Date:   Wed Dec 18 01:25:22 2013 -0700

    TODO: handle post data
---
 emacs-web-server-test.el |   23 +++++++++++++++++++++++
 emacs-web-server.el      |   18 ++++++++++++++----
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/emacs-web-server-test.el b/emacs-web-server-test.el
index 1e5e718..f5aa9c3 100644
--- a/emacs-web-server-test.el
+++ b/emacs-web-server-test.el
@@ -29,3 +29,26 @@
 (ert-deftest ews/parse-many-headers ()
   "Test that a number of headers parse successfully."
   (should t))
+
+(ert-deftest ews/parse-post-data ()
+  (let ((post-header
+         "POST / HTTP/1.1
+User-Agent: curl/7.33.0
+Host: localhost:8080
+Accept: */*
+Content-Length: 273
+Expect: 100-continue
+Content-Type: multipart/form-data; boundary=----------------f1270d0deb77af03
+
+------------------f1270d0deb77af03
+Content-Disposition: form-data; name=\"date\"
+
+Wed Dec 18 00:55:39 MST 2013
+
+------------------f1270d0deb77af03
+Content-Disposition: form-data; name=\"name\"
+
+\"schulte\"
+------------------f1270d0deb77af03--
+"))
+    (should 'properly-parse-post-data)))
diff --git a/emacs-web-server.el b/emacs-web-server.el
index 98530cd..461d012 100644
--- a/emacs-web-server.el
+++ b/emacs-web-server.el
@@ -8,6 +8,7 @@
 
 ;;; Code:
 (require 'emacs-web-server-status-codes)
+(require 'mail-parse)
 (require 'eieio)
 (require 'cl-lib)
 
@@ -98,22 +99,31 @@ function.
    (:otherwise (message "[ews] bad header: %S" string) nil)))
 
 (defun ews-filter (proc string)
+  ;; TODO: parse post DATA, see the relevent test, and use these
+  ;;   - mail-header-parse-content-disposition
+  ;;   - mail-header-parse-content-type
   (with-slots (handler clients) (plist-get (process-plist proc) :server)
     ;; register new client
     (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)
+           (last-index 0) index in-post)
       (catch 'finished-parsing-headers
         ;; parse headers and append to client
         (while (setq index (string-match "\r\n" pending last-index))
-          (when (= last-index index) ; double \r\n, done headers, call handler
+          ;; double \r\n outside of post data -> done w/headers, call handler
+          (when (and (not in-post) (= last-index index))
             (throw 'finished-parsing-headers
                    (when (ews-call-handler proc (cddr client) handler)
                      (setq clients (assq-delete-all proc clients))
                      (delete-process proc))))
-          (setcdr (last client)
-                  (ews-parse (substring pending last-index index)))
+          (if in-post
+              ;; build up post data, maybe set in-post to boundary
+              (error "TODO: handle POST data")
+            (let ((this (ews-parse (substring pending last-index index))))
+              (if (eql (caar this) :CONTENT-TYPE)
+                  (error "TODO: handle POST data")
+                (setcdr (last client) this))))
           (setq last-index (+ index 2)))
         (setcar (cdr client) (substring pending last-index))))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]