about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--.document7
-rw-r--r--DESIGN4
-rw-r--r--GNUmakefile8
-rw-r--r--LICENSE80
-rw-r--r--README8
-rw-r--r--ext/unicorn_http/global_variables.h6
-rw-r--r--ext/unicorn_http/unicorn_http.rl61
-rw-r--r--local.mk.sample2
8 files changed, 105 insertions, 71 deletions
diff --git a/.document b/.document
index 8f8ae75..e30a0dd 100644
--- a/.document
+++ b/.document
@@ -3,13 +3,8 @@ TUNING
 PHILOSOPHY
 DESIGN
 CONTRIBUTORS
-COPYING
 LICENSE
 SIGNALS
 TODO
-bin/unicorn
-bin/unicorn_rails
 lib
-ext/**/*.c
-ext/**/*.rl
-ext/**/*.h
+ext/unicorn_http/unicorn_http.c
diff --git a/DESIGN b/DESIGN
index 3543d9e..6be86be 100644
--- a/DESIGN
+++ b/DESIGN
@@ -11,8 +11,8 @@
   only non-Ruby part and there are no plans to add any more
   non-Ruby components.
 
-* All HTTP protocol parsing and I/O is done just like Mongrel:
-    1. read/parse HTTP request in full
+* All HTTP protocol parsing and I/O is done much like Mongrel:
+    1. read/parse HTTP request headers in full
     2. call Rack application
     3. write HTTP response back to the client
 
diff --git a/GNUmakefile b/GNUmakefile
index d0c3a0b..a3e0c5c 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -128,9 +128,11 @@ Manifest:
         cmp $@+ $@ || mv $@+ $@
         $(RM) -f $@+
 
-# using rdoc 2.4.1
-doc: .document
-        rdoc -Na -m README -t "$(shell sed -ne '1s/^= //p' README)"
+# using rdoc 2.4.1+
+doc: .document $(ext)/unicorn_http.c
+        rdoc -Na -t "$(shell sed -ne '1s/^= //p' README)"
+        install -m644 COPYING doc/COPYING
+        cd doc && ln README.html tmp.html && mv tmp.html index.html
 
 rails_git_url = git://github.com/rails/rails.git
 rails_git := vendor/rails.git
diff --git a/LICENSE b/LICENSE
index 5d38d9e..6265ac6 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,53 +1,55 @@
-Unicorn is copyrighted free software by Eric Wong (normalperson@yhbt.net)
-and contributors. You can redistribute it and/or modify it under either
-the terms of the GPL2 (see COPYING file) or the conditions below:
+Unicorn is copyrighted free software by Eric Wong
+(mailto:normalperson@yhbt.net) and contributors. You can redistribute it
+and/or modify it under either the terms of the
+{GPL2}[http://www.gnu.org/licenses/gpl-2.0.txt] (see link:COPYING) or
+the conditions below:
 
-1. You may make and give away verbatim copies of the source form of the
-   software without restriction, provided that you duplicate all of the
-   original copyright notices and associated disclaimers.
+  1. You may make and give away verbatim copies of the source form of the
+     software without restriction, provided that you duplicate all of the
+     original copyright notices and associated disclaimers.
 
-2. You may modify your copy of the software in any way, provided that
-   you do at least ONE of the following:
+  2. You may modify your copy of the software in any way, provided that
+     you do at least ONE of the following:
 
-     a) place your modifications in the Public Domain or otherwise make them
-     Freely Available, such as by posting said modifications to Usenet or an
-     equivalent medium, or by allowing the author to include your
-     modifications in the software.
+       a) place your modifications in the Public Domain or otherwise make them
+       Freely Available, such as by posting said modifications to Usenet or an
+       equivalent medium, or by allowing the author to include your
+       modifications in the software.
 
-     b) use the modified software only within your corporation or
-        organization.
+       b) use the modified software only within your corporation or
+          organization.
 
-     c) rename any non-standard executables so the names do not conflict with
-     standard executables, which must also be provided.
+       c) rename any non-standard executables so the names do not conflict with
+       standard executables, which must also be provided.
 
-     d) make other distribution arrangements with the author.
+       d) make other distribution arrangements with the author.
 
-3. You may distribute the software in object code or executable
-   form, provided that you do at least ONE of the following:
+  3. You may distribute the software in object code or executable
+     form, provided that you do at least ONE of the following:
 
-     a) distribute the executables and library files of the software,
-     together with instructions (in the manual page or equivalent) on where
-     to get the original distribution.
+       a) distribute the executables and library files of the software,
+       together with instructions (in the manual page or equivalent) on where
+       to get the original distribution.
 
-     b) accompany the distribution with the machine-readable source of the
-     software.
+       b) accompany the distribution with the machine-readable source of the
+       software.
 
-     c) give non-standard executables non-standard names, with
-        instructions on where to get the original software distribution.
+       c) give non-standard executables non-standard names, with
+          instructions on where to get the original software distribution.
 
-     d) make other distribution arrangements with the author.
+       d) make other distribution arrangements with the author.
 
-4. You may modify and include the part of the software into any other
-   software (possibly commercial).  But some files in the distribution
-   are not written by the author, so that they are not under this terms.
+  4. You may modify and include the part of the software into any other
+     software (possibly commercial).  But some files in the distribution
+     are not written by the author, so that they are not under this terms.
 
-5. The scripts and library files supplied as input to or produced as
-   output from the software do not automatically fall under the
-   copyright of the software, but belong to whomever generated them,
-   and may be sold commercially, and may be aggregated with this
-   software.
+  5. The scripts and library files supplied as input to or produced as
+     output from the software do not automatically fall under the
+     copyright of the software, but belong to whomever generated them,
+     and may be sold commercially, and may be aggregated with this
+     software.
 
-6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
-   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
-   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-   PURPOSE.
+  6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
+     IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+     PURPOSE.
diff --git a/README b/README
index aba9122..bf17f8d 100644
--- a/README
+++ b/README
@@ -1,10 +1,10 @@
-= Unicorn: Rack HTTP server for Unix, fast clients and nothing else
+= Unicorn: Rack HTTP server for Unix and fast clients
 
 == Features
 
 * Designed for Rack, Unix, fast clients, and ease-of-debugging.  We
   cut out everything that is better supported by the operating system,
-  nginx or Rack.
+  {nginx}[http://nginx.net/] or {Rack}[http://rack.rubyforge.org/].
 
 * Compatible with both Ruby 1.8 and 1.9, Rubinius support is planned.
 
@@ -60,7 +60,7 @@
 == License
 
 Unicorn is copyright 2009 Eric Wong and contributors.
-It is based on Mongrel and carries the same license:
+It is based on Mongrel and carries the same license.
 
 Mongrel is copyright 2007 Zed A. Shaw and contributors. It is licensed
 under the Ruby license and the GPL2. See the included LICENSE file for
@@ -162,7 +162,7 @@ requests) go to the mailing list/newsgroup.  Patches must be sent inline
 to post on the mailing list.  No top posting.  Address replies +To:+ (or
 +Cc:+) the original sender and +Cc:+ the mailing list.
 
-* email: mongrel-unicorn@rubyforge.org
+* email: mailto:mongrel-unicorn@rubyforge.org
 * nntp: nntp://news.gmane.org/gmane.comp.lang.ruby.unicorn.general
 * archives: http://rubyforge.org/pipermail/mongrel-unicorn/
 * subscribe: http://rubyforge.org/mailman/listinfo/mongrel-unicorn/
diff --git a/ext/unicorn_http/global_variables.h b/ext/unicorn_http/global_variables.h
index b8b6221..14aa77a 100644
--- a/ext/unicorn_http/global_variables.h
+++ b/ext/unicorn_http/global_variables.h
@@ -61,8 +61,6 @@ DEF_MAX_LENGTH(HEADER, (1024 * (80 + 32)));
 
 void init_globals(void)
 {
-  mUnicorn = rb_define_module("Unicorn");
-
   DEF_GLOBAL(rack_url_scheme, "rack.url_scheme");
   DEF_GLOBAL(request_method, "REQUEST_METHOD");
   DEF_GLOBAL(request_uri, "REQUEST_URI");
@@ -82,10 +80,6 @@ void init_globals(void)
   DEF_GLOBAL(http_11, "HTTP/1.1");
   DEF_GLOBAL(GET, "GET");
   DEF_GLOBAL(HEAD, "HEAD");
-
-  eHttpParserError =
-         rb_define_class_under(mUnicorn, "HttpParserError", rb_eIOError);
-  cHttpParser = rb_define_class_under(mUnicorn, "HttpParser", rb_cObject);
 }
 
 #undef DEF_GLOBAL
diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl
index 88fb163..19091f4 100644
--- a/ext/unicorn_http/unicorn_http.rl
+++ b/ext/unicorn_http/unicorn_http.rl
@@ -351,7 +351,7 @@ static VALUE HttpParser_alloc(VALUE klass)
 
 /**
  * call-seq:
- *    parser.new -> parser
+ *    parser.new => parser
  *
  * Creates a new parser.
  */
@@ -362,10 +362,9 @@ static VALUE HttpParser_init(VALUE self)
   return self;
 }
 
-
 /**
  * call-seq:
- *    parser.reset -> nil
+ *    parser.reset => nil
  *
  * Resets the parser to it's initial state so that you can reuse it
  * rather than making new ones.
@@ -391,6 +390,18 @@ static void advance_str(VALUE str, off_t nr)
   rb_str_set_len(str, len);
 }
 
+/**
+ * call-seq:
+ *   parser.content_length => nil or Integer
+ *
+ * Returns the number of bytes left to run through HttpParser#filter_body.
+ * This will initially be the value of the "Content-Length" HTTP header
+ * after header parsing is complete and will decrease in value as
+ * HttpParser#filter_body is called for each chunk.  This should return
+ * zero for requests with no body.
+ *
+ * This will return nil on "Transfer-Encoding: chunked" requests.
+ */
 static VALUE HttpParser_content_length(VALUE self)
 {
   struct http_parser *hp = data_get(self);
@@ -399,16 +410,24 @@ static VALUE HttpParser_content_length(VALUE self)
 }
 
 /**
+ * Document-method: trailers
+ * call-seq:
+ *    parser.trailers(req, data) => req or nil
+ *
+ * This is an alias for HttpParser#headers
+ */
+
+/**
+ * Document-method: headers
  * call-seq:
- *    parser.headers(req, data) -> req or nil
- *    parser.trailers(req, data) -> req or nil
+ *    parser.headers(req, data) => req or nil
  *
  * Takes a Hash and a String of data, parses the String of data filling
  * in the Hash returning the Hash if parsing is finished, nil otherwise
  * When returning the req Hash, it may modify data to point to where
- * body processing should begin
+ * body processing should begin.
  *
- * Raises HttpParserError if there are parsing errors
+ * Raises HttpParserError if there are parsing errors.
  */
 static VALUE HttpParser_headers(VALUE self, VALUE req, VALUE data)
 {
@@ -437,6 +456,13 @@ static int chunked_eof(struct http_parser *hp)
           (hp->flags & UH_FL_INTRAILER));
 }
 
+/**
+ * call-seq:
+ *    parser.body_eof? => true or false
+ *
+ * Detects if we're done filtering the body or not.  This can be used
+ * to detect when to stop calling HttpParser#filter_body.
+ */
 static VALUE HttpParser_body_eof(VALUE self)
 {
   struct http_parser *hp = data_get(self);
@@ -447,6 +473,17 @@ static VALUE HttpParser_body_eof(VALUE self)
   return hp->len.content == 0 ? Qtrue : Qfalse;
 }
 
+/**
+ * call-seq:
+ *    parser.keepalive? => true or false
+ *
+ * This should be used to detect if a request can really handle
+ * keepalives and pipelining.  Currently, the rules are:
+ *
+ * 1. MUST be a GET or HEAD request
+ * 2. MUST be HTTP/1.1 +or+ HTTP/1.0 with "Connection: keep-alive"
+ * 3. MUST NOT have "Connection: close" set
+ */
 static VALUE HttpParser_keepalive(VALUE self)
 {
   struct http_parser *hp = data_get(self);
@@ -456,7 +493,7 @@ static VALUE HttpParser_keepalive(VALUE self)
 
 /**
  * call-seq:
- *    parser.filter_body(buf, data) -> nil/data
+ *    parser.filter_body(buf, data) => nil/data
  *
  * Takes a String of +data+, will modify data if dechunking is done.
  * Returns +nil+ if there is more data left to process.  Returns
@@ -464,7 +501,7 @@ static VALUE HttpParser_keepalive(VALUE self)
  * it may modify +data+ so the start of the string points to where
  * the body ended so that trailer processing can begin.
  *
- * Raises HttpParserError if there are dechunking errors
+ * Raises HttpParserError if there are dechunking errors.
  * Basically this is a glorified memcpy(3) that copies +data+
  * into +buf+ while filtering it through the dechunker.
  */
@@ -523,6 +560,10 @@ end_of_body:
 
 void Init_unicorn_http(void)
 {
+  mUnicorn = rb_define_module("Unicorn");
+  eHttpParserError =
+         rb_define_class_under(mUnicorn, "HttpParserError", rb_eIOError);
+  cHttpParser = rb_define_class_under(mUnicorn, "HttpParser", rb_cObject);
   init_globals();
   rb_define_alloc_func(cHttpParser, HttpParser_alloc);
   rb_define_method(cHttpParser, "initialize", HttpParser_init,0);
@@ -545,7 +586,7 @@ void Init_unicorn_http(void)
   /*
    * The maximum size of the body as specified by Content-Length.
    * This is only a theoretical maximum, the actual limit is subject
-   * to the limits of the file system used for +Dir::tmpdir+
+   * to the limits of the file system used for +Dir.tmpdir+.
    */
   rb_define_const(cHttpParser, "LENGTH_MAX", OFFT2NUM(UH_OFF_T_MAX));
 
diff --git a/local.mk.sample b/local.mk.sample
index d218474..92c121b 100644
--- a/local.mk.sample
+++ b/local.mk.sample
@@ -38,7 +38,7 @@ publish_doc:
 # Create gzip variants of the same timestamp as the original so nginx
 # "gzip_static on" can serve the gzipped versions directly.
 doc_gz: suf := html js css
-doc_gz: docs = $(shell find doc/ -regex '^.*\.\(html\|js\|css\)$$')
+doc_gz: docs = $(shell find doc/ -regex '^.*\.\(html\|js\|css\)$$') doc/COPYING
 doc_gz:
         for i in $(docs); do \
           gzip --rsyncable < $$i > $$i.gz; touch -r $$i $$i.gz; done