2 #+Title: Notes and Tasks
3 #+HTML_HEAD: <style>pre{background:#232323; color:#E6E1DC;} table{margin:auto; width:50%;} @media(min-width:800px){div#content{max-width:800px; padding:2em; margin:auto;}}</style>
8 ** DONE Content and Transfer encodings
9 - Content and Transfer encoding values
10 http://www.iana.org/assignments/http-parameters/http-parameters.xhtml
11 - http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6
12 - http://en.wikipedia.org/wiki/Chunked_transfer_encoding
13 - http://tools.ietf.org/html/rfc1945#section-7.2
14 - http://tools.ietf.org/rfc/rfc1945.txt
16 Some issue as to whether compression is better done as a "Content
17 Encoding" which actually changes the content, or as a "Transfer
18 Encoding", which doesn't change the content, just the messages.
20 The latter seems preferable, but possibly less widely supported. See
21 http://stackoverflow.com/questions/11641923/transfer-encoding-gzip-vs-content-encoding-gzip.
24 - compress :: Unix =compress= program (rfc2616)
25 - deflate :: =zlib= (see http://www.iana.org/go/rfc1950) format with
26 =defalte= compression (rfc2616)
27 - exi :: W3c efficient XML (see http://www.w3.org/TR/exi/)
28 - gzip :: GNU zip (rfc2616)
29 - identity :: does nothing
30 - pack200-zip :: specific to Java archives (see
31 http://www.jcp.org/en/jsr/detail?id=200)
33 - chunked :: (rfc2616)
34 - compress :: same as above
35 - deflate :: same as above
36 - gzip :: same as above
38 - Content-MD5 :: Base64 encoded binary MD5 sum of content
40 Maybe we can set the coding system of the process with
41 =define-coding-system=, specifically using the =:pre-write-conversion=
42 flag to e.g., gzip or chunkify the contents.
45 - http://en.wikipedia.org/wiki/WebSocket
46 - http://tools.ietf.org/html/rfc6455
48 ** more examples [4/4]
49 *** DONE Org-mode agenda
50 Already exists as part of org-ehtml.
51 file:examples/011-org-agenda.el
53 *** DONE display the current buffer
54 Idea stolen from elnode.
55 file:examples/010-current-buffer.el
57 *** DONE browse the BBDB
58 file:examples/012-search-bbdb.el
59 *** DONE org-mode export server
61 2. supply an export type
62 3. return the exported version of the file
64 ** DONE handle large files
65 When large files arrive quickly, the filter functions are called while
66 they are still running on the previous chunk, this leads to nasty race
67 conditions for the state of the request object.
69 Either introduce some check to wait on new input if input is currently
70 being parsed, or wait until all input has arrived before doing any
73 Now using an =active= field on request objects to avoid race
74 conditions when new header text is received while the parsing function
77 ** TODO robustness to bad requests [0/2]
78 Low priority, just [[*running%20behind%20a%20proxy][run behind a proxy]].
80 *** TODO request timeout
81 *** TODO maximum request size
82 ** DONE authentication [2/2]
83 - State "HOLD" from "TODO" [2014-02-10 Mon 19:06] \\
84 digest may not be worth it, just run Basic over HTTPS
86 http://en.wikipedia.org/wiki/Basic_access_authentication
89 http://en.wikipedia.org/wiki/Digest_access_authentication
91 If this is implemented, it would be good to implement some safeguards
92 against common attacks.
95 - Server nonce is allowed to contain timestamps. Therefore the server
96 may inspect nonce attributes submitted by clients, to prevent replay
98 - Server is also allowed to maintain a list of recently issued or used
99 server nonce values to prevent reuse.
102 ** incremental handler calls
103 not sure if the extra performance is worth the added complexity
105 Before the header is fully parsed, call any potential handlers.
106 Include a field in the request object to indicate that the request
107 isn't finished being received so handlers can return and wait to be
110 Also, put a catch in the filter function and allow the =headers=
111 function on the request object to throw to said catch aborting the
112 handler and waiting for the rest of the input.
114 ** DONE Documentation [6/6]
117 - [X] request headers
119 - [X] list of functions
122 - [X] how to set content type
124 ** DONE Handle POST requests
125 1. read standard for POST data
126 2. parse multi-line headers with boundaries
128 For now keep this all incremental and in ws-filter.
135 ** DONE catch errors and return an error code
136 include an easy error handler like the 404 handler
138 ** DONE better parsing of multipart form blocks
139 parse more than just the content-type headers.
141 ** DONE non-multipart form data
142 e.g., parameter strings
144 ** DONE some more convenience functionality [6/6]
145 - [X] strip and parse URL query string
146 - [X] parse urlencoded post data
147 - [X] think about defaulting to (name . content) for form elements
148 - [X] maybe don't require a non-nil return to cancel the connection,
149 instead only keep open if =:keep-alive= is returned
150 - [X] function to send a file (with mime handling)
151 - [X] send a 404 with some default text
153 ** CANCELED Lazy header processing
154 - State "CANCELED" from "TODO" [2013-12-25 Wed 12:21] \\
155 premature optimization
156 Use lazy sequence functions for header a-list to avoid parsing all
157 headers. For regexp matchers should stop when matched header is
158 encountered (often the first one when :GET), For function matchers
159 provide lazy version of assoc.
161 Also, there is the issue of how a lazy request for more parameters
162 should act before all incoming text has been received. Emacs does not
163 provide a light-weight mechanism for a function to wait for incoming
164 process text without something gross like the =(sit-for 0.1)= used in
167 ** use gnutls for https
168 low priority -- just [[*running%20behind%20an%20https%20proxy][run behind an https proxy]].
170 This will be a pain, and will require expanding [[info:emacs-gnutls]] to
171 add support for starting server processes, currently only client
172 processes are supported.
174 - http://en.wikipedia.org/wiki/XVidCap
175 - https://aur.archlinux.org/packages/xvidcap/
178 The following tutorials walk through common usage scenarios including
179 installing the Emacs web-server and running it behind a proxy.
180 Install the Emacs web-server and run =(info "web-server")= to browse
181 the full manual within Emacs, or view the HTML version at
182 [[http://eschulte.github.io/emacs-web-server/][emacs-web-server]].
184 ** Installation and running a server
185 Most easily installable through the GNU ELPA, run =M-x
186 package-list-packages= select =web-server= and install. Alternately,
187 install from the git repository at
188 https://github.com/eschulte/emacs-web-server and update your the load.
190 1. Ensure that you have Emacs version 24 or greater installed.
192 #+begin_src sh :results scalar
197 : Copyright (C) 2013 Free Software Foundation, Inc.
198 : GNU Emacs comes with ABSOLUTELY NO WARRANTY.
199 : You may redistribute copies of Emacs
200 : under the terms of the GNU General Public License.
201 : For more information about these matters, see the file named COPYING.
203 2. Download and unpack the zip archive of the Emacs web-server code
204 from [[https://github.com/eschulte/emacs-web-server/archive/master.zip][emacs-web-server-master.zip]] or clone the source code
205 repository with [[http://git-scm.com/][git]].
208 git clone https://github.com/eschulte/emacs-web-server.git
211 3. Move into the root of the =emacs-web-server/= directory and
212 optionally run =make= to compile the web-server code, and run =make
213 check= to test your web-server install.
220 4. From the root of the =emacs-web-server/= directory, start an
221 instance of Emacs with web-server loaded.
224 emacs -Q -L . -l web-server
227 Alternately, from an already running Emacs instance, add this
228 directory to the load path and load the web server with the
231 #+begin_src emacs-lisp
232 (add-to-list 'load-path "path/to/emacs-web-server")
233 (require 'web-server)
236 5. Evaluate the following code in =*scratch*= buffer of this Emacs
239 #+begin_src emacs-lisp
242 (with-slots (process headers) request
243 (ws-response-header process 200 '("Content-type" . "text/plain"))
244 (process-send-string process "hello world")))
248 6. Browse to http://localhost:9000 to see that the web-server is
251 7. Read the web-server [[http://eschulte.github.io/emacs-web-server/index.html#Top][manual]] and work through other [[http://eschulte.github.io/emacs-web-server/Usage-Examples.html#Usage-Examples][Usage Examples]].
253 ** Running behind a proxy
254 Public-facing instance of the Emacs web-server should be run behind a
255 more established web server such as [[http://httpd.apache.org/][Apache]] or [[http://wiki.nginx.org][Nginx]] to provide
256 additional robustness and security.
258 The following example Apache configuration may be used to have a
259 public facing Apache server listening on port 80 proxy requests to a
260 local web-server instance running on port 8888 of the same machine.
264 ServerName yourserver.com
266 ProxyPass / http://localhost:8888/
270 A similar Nginx configuration is available at
271 http://wiki.nginx.org/LoadBalanceExample.
273 ** Running behind an https proxy
274 The following example configurations will cause Apache or Nginx to act
275 as an HTTPS proxy for an instance of the Emacs web server running on
276 the same machine. With this setup Apache speaks HTTPS to the outside
277 world, and communicates with the Emacs web server using HTTP. This
278 allows use of HTTPS even though the Emacs web server does not
279 implement HTTPS itself. This setup is recommended for any setup, but
280 should be considered *required* for sites using BASIC HTTP
284 This requires that Apache has =mod_proxy= and =mod_ssl= enabled, and
285 that the certificate and key files required for SSL are present. This
286 these requirements satisfied, and assuming the Emacs web server is
287 listening on port 8888 and is running on the same machine as the
288 Apache web server an Apache virtual host configuration such as the
294 ServerName yourserver.com
297 SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
298 SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
300 ProxyPass / http://localhost:8888/
301 ProxyPassReverse / http://localhost:8888/
306 See the following for instructions configuring Nginx as an HTTPS
308 - http://wiki.nginx.org/SSL-Offloader#sslproxy.conf
309 - http://www.cyberciti.biz/faq/howto-linux-unix-setup-nginx-ssl-proxy/
311 ** COMMENT documentation for running in a chroot jail
312 See https://wiki.archlinux.org/index.php/nginx#Installation_in_a_chroot.
315 ** DONE Sometimes servers don't stop cleanly
316 - specifically servers with active client process
317 - maybe also implement a =ws-stop-all= function