From 12dbc0dfbd7e74507b67bd5b2488278336778cde Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Fri, 31 Jan 2020 17:56:39 +0100 Subject: [PATCH] update simple-httpd --- .../simple-httpd-pkg.el | 2 - .../simple-httpd-autoloads.el | 11 ++- .../simple-httpd-pkg.el | 2 + .../simple-httpd.el | 13 ++- elpa/simple-httpd-readme.txt | 83 +++++++++++++++++++ 5 files changed, 103 insertions(+), 8 deletions(-) delete mode 100644 elpa/simple-httpd-20191006.1956/simple-httpd-pkg.el rename elpa/{simple-httpd-20191006.1956 => simple-httpd-20191103.1446}/simple-httpd-autoloads.el (71%) create mode 100644 elpa/simple-httpd-20191103.1446/simple-httpd-pkg.el rename elpa/{simple-httpd-20191006.1956 => simple-httpd-20191103.1446}/simple-httpd.el (98%) create mode 100644 elpa/simple-httpd-readme.txt diff --git a/elpa/simple-httpd-20191006.1956/simple-httpd-pkg.el b/elpa/simple-httpd-20191006.1956/simple-httpd-pkg.el deleted file mode 100644 index b91586cf..00000000 --- a/elpa/simple-httpd-20191006.1956/simple-httpd-pkg.el +++ /dev/null @@ -1,2 +0,0 @@ -;;; -*- no-byte-compile: t -*- -(define-package "simple-httpd" "20191006.1956" "pure elisp HTTP server" '((cl-lib "0.3")) :commit "67f2f1e665fa66d7ef3beed8e82f94962bfa4f3b" :authors '(("Christopher Wellons" . "wellons@nullprogram.com")) :maintainer '("Christopher Wellons" . "wellons@nullprogram.com") :url "https://github.com/skeeto/emacs-http-server") diff --git a/elpa/simple-httpd-20191006.1956/simple-httpd-autoloads.el b/elpa/simple-httpd-20191103.1446/simple-httpd-autoloads.el similarity index 71% rename from elpa/simple-httpd-20191006.1956/simple-httpd-autoloads.el rename to elpa/simple-httpd-20191103.1446/simple-httpd-autoloads.el index 287ff524..a042623f 100644 --- a/elpa/simple-httpd-20191006.1956/simple-httpd-autoloads.el +++ b/elpa/simple-httpd-20191103.1446/simple-httpd-autoloads.el @@ -1,10 +1,12 @@ ;;; simple-httpd-autoloads.el --- automatically extracted autoloads ;; ;;; Code: -(add-to-list 'load-path (directory-file-name (or (file-name-directory #$) (car load-path)))) + +(add-to-list 'load-path (directory-file-name + (or (file-name-directory #$) (car load-path)))) + -;;;### (autoloads nil "simple-httpd" "simple-httpd.el" (23994 46381 -;;;;;; 779474 32000)) +;;;### (autoloads nil "simple-httpd" "simple-httpd.el" (0 0 0 0)) ;;; Generated autoloads from simple-httpd.el (autoload 'httpd-start "simple-httpd" "\ @@ -29,11 +31,14 @@ Start the web server with given `directory' as `httpd-root'. \(fn DIRECTORY)" t nil) +(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "simple-httpd" '("httpd" "defservlet" "with-httpd-buffer"))) + ;;;*** ;; Local Variables: ;; version-control: never ;; no-byte-compile: t ;; no-update-autoloads: t +;; coding: utf-8 ;; End: ;;; simple-httpd-autoloads.el ends here diff --git a/elpa/simple-httpd-20191103.1446/simple-httpd-pkg.el b/elpa/simple-httpd-20191103.1446/simple-httpd-pkg.el new file mode 100644 index 00000000..86794ddd --- /dev/null +++ b/elpa/simple-httpd-20191103.1446/simple-httpd-pkg.el @@ -0,0 +1,2 @@ +;;; -*- no-byte-compile: t -*- +(define-package "simple-httpd" "20191103.1446" "pure elisp HTTP server" '((cl-lib "0.3")) :commit "22ce66ea43e0eadb9ec1d691a35d9695fc29cee6" :authors '(("Christopher Wellons" . "wellons@nullprogram.com")) :maintainer '("Christopher Wellons" . "wellons@nullprogram.com") :url "https://github.com/skeeto/emacs-http-server") diff --git a/elpa/simple-httpd-20191006.1956/simple-httpd.el b/elpa/simple-httpd-20191103.1446/simple-httpd.el similarity index 98% rename from elpa/simple-httpd-20191006.1956/simple-httpd.el rename to elpa/simple-httpd-20191103.1446/simple-httpd.el index 4c75a840..9801b970 100644 --- a/elpa/simple-httpd-20191006.1956/simple-httpd.el +++ b/elpa/simple-httpd-20191103.1446/simple-httpd.el @@ -4,7 +4,7 @@ ;; Author: Christopher Wellons ;; URL: https://github.com/skeeto/emacs-http-server -;; Package-Version: 20191006.1956 +;; Package-Version: 20191103.1446 ;; Version: 1.5.1 ;; Package-Requires: ((cl-lib "0.3")) @@ -828,7 +828,8 @@ the `httpd-current-proc' as the process." (httpd-send-header proc "text/plain" 304)) (httpd-log `(file ,path)) (with-temp-buffer - (insert-file-contents path) + (set-buffer-multibyte nil) + (insert-file-contents-literally path) (httpd-send-header proc (httpd-get-mime (file-name-extension path)) 200 :Last-Modified mtime :ETag etag))))) @@ -858,7 +859,13 @@ the `httpd-current-proc' as the process." (defun httpd--buffer-size (&optional buffer) "Get the buffer size in bytes." - (bufferpos-to-filepos (point-max))) + (let ((orig enable-multibyte-characters) + (size 0)) + (with-current-buffer (or buffer (current-buffer)) + (set-buffer-multibyte nil) + (setf size (buffer-size)) + (if orig (set-buffer-multibyte orig))) + size)) (defun httpd-error (proc status &optional info) "Send an error page appropriate for STATUS to the client, diff --git a/elpa/simple-httpd-readme.txt b/elpa/simple-httpd-readme.txt new file mode 100644 index 00000000..9a35fdb3 --- /dev/null +++ b/elpa/simple-httpd-readme.txt @@ -0,0 +1,83 @@ +Use `httpd-start' to start the web server. Files are served from +`httpd-root' on port `httpd-port' using `httpd-ip-family' at host +`httpd-host'. While the root can be changed at any time, the server +needs to be restarted in order for a port change to take effect. + +Everything is performed by servlets, including serving +files. Servlets are enabled by setting `httpd-servlets' to true +(default). Servlets are four-parameter functions that begin with +"httpd/" where the trailing component specifies the initial path on +the server. For example, the function `httpd/hello-world' will be +called for the request "/hello-world" and "/hello-world/foo". + +The default servlet `httpd/' is the one that serves files from +`httpd-root' and can be turned off through redefinition or setting +`httpd-serve-files' to nil. It is used even when `httpd-servlets' +is nil. + +The four parameters for a servlet are process, URI path, GET/POST +arguments (alist), and the full request object (header +alist). These are ordered by general importance so that some can be +ignored. Two macros are provided to help with writing servlets. + + * `with-httpd-buffer' -- Creates a temporary buffer that is + automatically served to the client at the end of the body. + Additionally, `standard-output' is set to this output + buffer. For example, this servlet says hello, + + (defun httpd/hello-world (proc path &rest args) + (with-httpd-buffer proc "text/plain" + (insert "hello, " (file-name-nondirectory path)))) + +This servlet be viewed at http://localhost:8080/hello-world/Emacs + +* `defservlet' -- Similar to the above macro but totally hides the + process object from the servlet itself. The above servlet can be + re-written identically like so, + + (defservlet hello-world text/plain (path) + (insert "hello, " (file-name-nondirectory path))) + +Note that `defservlet' automatically sets `httpd-current-proc'. See +below. + +The "function parameters" part can be left empty or contain up to +three parameters corresponding to the final three servlet +parameters. For example, a servlet that shows *scratch* and doesn't +need parameters, + + (defservlet scratch text/plain () + (insert-buffer-substring (get-buffer-create "*scratch*"))) + +A higher level macro `defservlet*' wraps this lower-level +`defservlet' macro, automatically binding variables to components +of the request. For example, this binds parts of the request path +and one query parameter. Request components not provided by the +client are bound to nil. + + (defservlet* packages/:package/:version text/plain (verbose) + (insert (format "%s\n%s\n" package version)) + (princ (get-description package version)) + (when verbose + (insert (format "%S" (get-dependencies package version))))) + +It would be accessed like so, + + http://example.com/packages/foobar/1.0?verbose=1 + +Some support functions are available for servlets for more +customized responses. + + * `httpd-send-file' -- serve a file with proper caching + * `httpd-redirect' -- redirect the browser to another url + * `httpd-send-header' -- send custom headers + * `httpd-error' -- report an error to the client + * `httpd-log' -- log an object to *httpd* + +Some of these functions require a process object, which isn't +passed to `defservlet' servlets. Use t in place of the process +argument to use `httpd-current-proc' (like `standard-output'). + +If you just need to serve static from some location under some +route on the server, use `httpd-def-file-servlet'. It expands into +a `defservlet' that serves files. -- 2.47.3