[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 24/119: parse application/x-www-form-urlencoded post data
From: |
Eric Schulte |
Subject: |
[elpa] 24/119: parse application/x-www-form-urlencoded post data |
Date: |
Mon, 10 Mar 2014 16:57:07 +0000 |
eschulte pushed a commit to branch master
in repository elpa.
commit 1b272794e2b2efd3a388ad1fcac29c7399376d66
Author: Eric Schulte <address@hidden>
Date: Wed Dec 18 23:47:11 2013 -0700
parse application/x-www-form-urlencoded post data
---
NOTES | 7 ++++---
emacs-web-server.el | 26 ++++++++++++++++++++------
2 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/NOTES b/NOTES
index 2024910..07e7305 100644
--- a/NOTES
+++ b/NOTES
@@ -1,7 +1,7 @@
-*- org -*-
* Notes
-* Tasks [3/8]
+* Tasks [4/8]
** DONE Handle POST requests
1. read standard for POST data
2. parse multi-line headers with boundaries
@@ -19,11 +19,12 @@ include an easy error handler like the 404 handler
** TODO better parsing of multipart form blocks
parse more than just the content-type headers.
-** TODO non-multipart form data
+** DONE non-multipart form data
e.g., parameter strings
-** TODO some more convenience functionality [4/5]
+** TODO some more convenience functionality [5/6]
- [ ] strip and parse URL query string
+- [X] parse urlencoded post data
- [X] think about defaulting to (name . content) for form elements
- [X] maybe don't require a non-nil return to cancel the connection,
instead only keep open if :keep-open is returned
diff --git a/emacs-web-server.el b/emacs-web-server.el
index efcfb5c..d24da78 100644
--- a/emacs-web-server.el
+++ b/emacs-web-server.el
@@ -155,7 +155,17 @@ function.
(cond
;; Double \r\n outside of post data means we are done
;; w/headers and should call the handler.
- ((= last-index index)
+ ((and (not boundary) (= last-index index))
+ (throw 'finished-parsing-headers t))
+ ;; Parse a URL
+ ((eq boundary :application/x-www-form-urlencoded)
+ (mapc (lambda (p)
+ (when (string-match "=" p)
+ (setcdr (last headers)
+ (list (cons (substring p 0 (match-beginning 0))
+ (substring p (match-end 0)))))))
+ (split-string (ews-trim (substring pending last-index))
+ "&" 'omit-nulls))
(throw 'finished-parsing-headers t))
;; Build up multipart data.
(boundary
@@ -173,11 +183,15 @@ function.
(if (and (caar this) (eql (caar this) :CONTENT-TYPE))
(cl-destructuring-bind (type &rest data)
(mail-header-parse-content-type (cdar this))
- (unless (string= type "multipart/form-data")
- (ews-error proc "TODO: handle content type: %S" type))
- (when (assoc 'boundary data)
- (setq boundary (cdr (assoc 'boundary data)))
- (setq delimiter (concat "\r\n--" boundary))))
+ (cond
+ ((string= type "multipart/form-data")
+ (when (assoc 'boundary data)
+ (setq boundary (cdr (assoc 'boundary data)))
+ (setq delimiter (concat "\r\n--" boundary))))
+ ((string= type "application/x-www-form-urlencoded")
+ (setq boundary (intern (concat ":" (downcase type)))))
+ (:otherwise
+ (ews-error proc "TODO: handle content type: %S"
type))))
(setcdr (last headers) this)))))
(setq last-index tmp)))
(setq leftover (ews-trim (substring pending last-index)))
- [elpa] 18/119: 404 not found helper, (continued)
- [elpa] 18/119: 404 not found helper, Eric Schulte, 2014/03/10
- [elpa] 17/119: handling errors, Eric Schulte, 2014/03/10
- [elpa] 14/119: better requirements for test, Eric Schulte, 2014/03/10
- [elpa] 16/119: tasks, Eric Schulte, 2014/03/10
- [elpa] 20/119: don't require non-nil return to close connection, Eric Schulte, 2014/03/10
- [elpa] 19/119: simply (name . content) for form elements, Eric Schulte, 2014/03/10
- [elpa] 21/119: helper to send a file with mime type, Eric Schulte, 2014/03/10
- [elpa] 22/119: file serving example, Eric Schulte, 2014/03/10
- [elpa] 23/119: handle close-connection thrown during header parse, Eric Schulte, 2014/03/10
- [elpa] 25/119: seems to be generally usable, added a README, Eric Schulte, 2014/03/10
- [elpa] 24/119: parse application/x-www-form-urlencoded post data,
Eric Schulte <=
- [elpa] 26/119: thread proc through some functions, Eric Schulte, 2014/03/10
- [elpa] 28/119: testing a hello-world server, Eric Schulte, 2014/03/10
- [elpa] 27/119: run test processes asynch, Eric Schulte, 2014/03/10
- [elpa] 29/119: update examples, Eric Schulte, 2014/03/10
- [elpa] 31/119: match more HTTP methods, Eric Schulte, 2014/03/10
- [elpa] 30/119: fleshed out some more tests, Eric Schulte, 2014/03/10
- [elpa] 32/119: url-encoded parameters, Eric Schulte, 2014/03/10
- [elpa] 34/119: found a confounding POST example, Eric Schulte, 2014/03/10
- [elpa] 33/119: ews-subdirectoryp convenience function, Eric Schulte, 2014/03/10
- [elpa] 36/119: bug fix, Eric Schulte, 2014/03/10