branch: elpa/simple-httpd
commit ffe5956bc539999b77021745fd1da118c76037d2
Author: Daniel Mendler <[email protected]>
Commit: Daniel Mendler <[email protected]>
Add httpd-filter-functions to filter or rewrite requests
---
simple-httpd.el | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/simple-httpd.el b/simple-httpd.el
index 417501d9ad..6c2eb33bcf 100644
--- a/simple-httpd.el
+++ b/simple-httpd.el
@@ -156,6 +156,10 @@ Set to nil to disable logging."
"Hook to run when the server has stopped."
:type 'hook)
+(defcustom httpd-filter-functions nil
+ "Functions called with request as argument, should return modified request."
+ :type 'hook)
+
(defcustom httpd-server-name (format "simple-httpd (Emacs %s)" emacs-version)
"String to use in the Server header."
:type '(choice (const nil) string))
@@ -391,7 +395,12 @@ Logs are redirected to stdout. To use, invoke Emacs like
this:
(defun httpd--handle-request (proc request)
"Handle REQUEST from client PROC."
(condition-case err
- (let* ((uri (cadar request))
+ (let* ((_ (run-hook-wrapped
+ 'httpd-filter-functions
+ (lambda (fun)
+ (setq request (funcall fun request))
+ nil)))
+ (uri (cadar request))
(parsed-uri (httpd-parse-uri (concat uri)))
(uri-path (car parsed-uri))
(uri-query (nconc (cadr parsed-uri)