nginx-0.1.9-RELEASE import

    *) Bugfix: the proxied request was sent without arguments if the
       request contains "//", "/./", "/../" or "%XX".

    *) Bugfix: the large compressed responses may be transferred not
       completely.

    *) Bugfix: the files bigger than 2G was not transferred on Linux that
       does not support sendfile64().

    *) Bugfix: while the build configuration on Linux the
       --with-poll_module parameter was required; the bug had appeared in
       0.1.8.
diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c
index f8980af..b093d58 100644
--- a/src/http/modules/ngx_http_gzip_filter.c
+++ b/src/http/modules/ngx_http_gzip_filter.c
@@ -237,14 +237,14 @@
 
 static u_char  gzheader[10] = { 0x1f, 0x8b, Z_DEFLATED, 0, 0, 0, 0, 0, 0, 3 };
 
-#if (HAVE_LITTLE_ENDIAN)
+#if (NGX_HAVE_LITTLE_ENDIAN)
 
 struct gztrailer {
     uint32_t  crc32;
     uint32_t  zlen;
 };
 
-#else /* HAVE_BIG_ENDIAN */
+#else /* NGX_HAVE_BIG_ENDIAN */
 
 struct gztrailer {
     u_char  crc32[4];
@@ -437,7 +437,8 @@
 static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r,
                                            ngx_chain_t *in)
 {
-    int                    rc, wbits, memlevel, last;
+    int                    rc, wbits, memlevel;
+    ngx_int_t              last;
     struct gztrailer      *trailer;
     ngx_buf_t             *b;
     ngx_chain_t           *cl;
@@ -469,7 +470,7 @@
         /*
          * We preallocate a memory for zlib in one buffer (200K-400K), this
          * dicreases a number of malloc() and free() calls and also probably
-         * dicreases a number of syscalls (sbrk() or so).
+         * dicreases a number of syscalls (sbrk() and so on).
          * Besides we free this memory as soon as the gzipping will complete
          * and do not wait while a whole response will be sent to a client.
          *
@@ -512,8 +513,19 @@
         }
         cl->buf = b;
         cl->next = NULL;
-        ctx->out = cl;
-        ctx->last_out = &cl->next;
+
+        /*
+         * We pass the gzheader to the next filter now to avoid its linking
+         * to the ctx->busy chain.  zlib does not usually output the compressed
+         * data in the initial iterations, so the gzheader that was linked
+         * to the ctx->busy chain would be flushed by ngx_http_write_filter().
+         */
+
+        if (ngx_http_next_body_filter(r, cl) == NGX_ERROR) {
+            return ngx_http_gzip_error(ctx);
+        }
+
+        ctx->last_out = &ctx->out;
 
         ctx->crc32 = crc32(0L, Z_NULL, 0);
         ctx->flush = Z_NO_FLUSH;
@@ -727,7 +739,7 @@
                     b->last += 8;
                 }
 
-#if (HAVE_LITTLE_ENDIAN)
+#if (NGX_HAVE_LITTLE_ENDIAN)
                 trailer->crc32 = ctx->crc32;
                 trailer->zlen = ctx->zin;
 #else
@@ -763,7 +775,7 @@
             }
         }
 
-        if (last == NGX_AGAIN) {
+        if (last == NGX_AGAIN && !ctx->done) {
             return NGX_AGAIN;
         }
 
@@ -881,7 +893,9 @@
 {
     deflateEnd(&ctx->zstream);
 
-    ngx_pfree(ctx->request->pool, ctx->preallocated);
+    if (ctx->preallocated) {
+        ngx_pfree(ctx->request->pool, ctx->preallocated);
+    }
 
     ctx->zstream.avail_in = 0;
     ctx->zstream.avail_out = 0;
diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c
index 013f62b..3386953 100644
--- a/src/http/modules/ngx_http_index_handler.c
+++ b/src/http/modules/ngx_http_index_handler.c
@@ -10,19 +10,19 @@
 
 
 typedef struct {
-    ngx_array_t             indices;
-    size_t                  max_index_len;
-    ngx_http_cache_hash_t  *index_cache;
+    ngx_array_t              indices;
+    size_t                   max_index_len;
+    ngx_http_cache_hash_t   *index_cache;
 } ngx_http_index_loc_conf_t;
 
 
 typedef struct {
-    ngx_uint_t         index;
-    u_char            *last;
-    ngx_str_t          path;
-    ngx_str_t          redirect;
-    ngx_http_cache_t  *cache;
-    unsigned           tested:1;
+    ngx_uint_t               index;
+    u_char                  *last;
+    ngx_str_t                path;
+    ngx_str_t                redirect;
+    ngx_http_cache_entry_t  *cache;
+    ngx_uint_t               tested; /* unsigned  tested:1 */
 } ngx_http_index_ctx_t;
 
 
diff --git a/src/http/modules/proxy/ngx_http_proxy_cache.c b/src/http/modules/proxy/ngx_http_proxy_cache.c
index f0b56f5..86b8424 100644
--- a/src/http/modules/proxy/ngx_http_proxy_cache.c
+++ b/src/http/modules/proxy/ngx_http_proxy_cache.c
@@ -297,7 +297,7 @@
 
     if (rc == NGX_AGAIN) {
 
-        if ((ngx_event_flags & (NGX_USE_CLEAR_EVENT|NGX_HAVE_KQUEUE_EVENT))
+        if ((ngx_event_flags & (NGX_USE_CLEAR_EVENT|NGX_USE_KQUEUE_EVENT))
             && !p->request->connection->write->active)
         {
             /*
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index c0a8cf3..425a1a6 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -414,7 +414,7 @@
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0,
                    "http proxy check client, write event:%d", ev->write);
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 
     if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
 
@@ -563,9 +563,9 @@
      */
 
 #if 0
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 
-    if ((ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) && rev->kq_eof) {
+    if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT) && rev->kq_eof) {
         ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
 
         ngx_del_timer(rev);
@@ -1400,7 +1400,7 @@
         return NGX_CONF_ERROR;
     }
 
-#elif !(HAVE_SO_SNDLOWAT)
+#elif !(NGX_HAVE_SO_SNDLOWAT)
 
     ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
                        "\"proxy_send_lowat\" is not supported, ignored");
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h
index 094ee3b..8ab88ad 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.h
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.h
@@ -142,7 +142,7 @@
 
 
 typedef struct {
-    ngx_http_cache_ctx_t             ctx;
+    ngx_http_cache_t                 ctx;
     ngx_uint_t                       status;
     ngx_str_t                        status_line;
 
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index 0852a42..23d40c4 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -782,7 +782,7 @@
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
                    "http proxy send request");
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 
     if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT)
         && !p->request_sent
@@ -1287,8 +1287,8 @@
         header->length = r->headers_out.content_length_n;
         p->cache->ctx.length = r->headers_out.content_length_n;
 
-        header->key_len = p->cache->ctx.key.len;
-        ngx_memcpy(&header->key, p->cache->ctx.key.data, header->key_len);
+        header->key_len = p->cache->ctx.key0.len;
+        ngx_memcpy(&header->key, p->cache->ctx.key0.data, header->key_len);
         header->key[header->key_len] = LF;
     }
 
diff --git a/src/http/ngx_http_cache.c b/src/http/ngx_http_cache.c
index 22572a5..abdeae9 100644
--- a/src/http/ngx_http_cache.c
+++ b/src/http/ngx_http_cache.c
@@ -63,7 +63,7 @@
 
             c[i].refs++;
 
-            if ((!(c[i].notify && (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT)))
+            if ((!(c[i].notify && (ngx_event_flags & NGX_USE_KQUEUE_EVENT)))
                 && (ngx_cached_time - c[i].updated >= hash->update))
             {
                 c[i].expired = 1;
diff --git a/src/http/ngx_http_cache.h b/src/http/ngx_http_cache.h
index 40f4852..aa66902 100644
--- a/src/http/ngx_http_cache.h
+++ b/src/http/ngx_http_cache.h
@@ -14,11 +14,12 @@
 
 
 /*
- * The 7 uses before an allocation.
+ * The 3 bits allows the 7 uses before the cache entry allocation.
  * We can use maximum 7 bits, i.e up to the 127 uses.
  */
 #define NGX_HTTP_CACHE_LAZY_ALLOCATION_BITS  3
 
+
 typedef struct {
     uint32_t         crc;
     ngx_str_t        key;
@@ -45,7 +46,7 @@
         off_t        size;
         ngx_str_t    value;
     } data;
-} ngx_http_cache_t;
+} ngx_http_cache_entry_t;
 
 
 typedef struct {
@@ -62,7 +63,7 @@
 #define NGX_HTTP_CACHE_NELTS  4
 
 typedef struct {
-    ngx_http_cache_t         *elts;
+    ngx_http_cache_entry_t   *elts;
     size_t                    hash;
     size_t                    nelts;
     time_t                    life;
@@ -76,9 +77,9 @@
 
 typedef struct {
     ngx_http_cache_hash_t    *hash;
-    ngx_http_cache_t         *cache;
+    ngx_http_cache_entry_t   *cache;
     ngx_file_t                file;
-    ngx_str_t                 key;
+    ngx_array_t               key;
     uint32_t                  crc;
     u_char                    md5[16];
     ngx_path_t               *path;
@@ -90,7 +91,10 @@
     ssize_t                   header_size;
     size_t                    file_start;
     ngx_log_t                *log;
-} ngx_http_cache_ctx_t;
+
+    /* STUB */
+    ngx_str_t                 key0;
+} ngx_http_cache_t;
 
 
 
@@ -99,6 +103,8 @@
 #define NGX_HTTP_CACHE_THE_SAME  3
 
 
+#if 0
+
 ngx_http_cache_t *ngx_http_cache_get(ngx_http_cache_hash_t *cache,
                                      ngx_http_cleanup_t *cleanup,
                                      ngx_str_t *key, uint32_t *crc);
@@ -127,5 +133,7 @@
 
 char *ngx_http_set_cache_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
 
+#endif
+
 
 #endif /* _NGX_HTTP_CACHE_H_INCLUDED_ */
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index c764b2a..c4cb8b9 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -1828,7 +1828,7 @@
         return NGX_CONF_ERROR;
     }
 
-#elif !(HAVE_SO_SNDLOWAT)
+#elif !(NGX_HAVE_SO_SNDLOWAT)
 
     ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
                        "\"send_lowat\" is not supported, ignored");
diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c
index 8f920d2..1b258c9 100644
--- a/src/http/ngx_http_file_cache.c
+++ b/src/http/ngx_http_file_cache.c
@@ -9,19 +9,20 @@
 #include <ngx_http.h>
 
 
-#if (HAVE_OPENSSL_MD5_H)
+#if (NGX_HAVE_OPENSSL_MD5_H)
 #include <openssl/md5.h>
 #else
 #include <md5.h>
 #endif
 
-#if (HAVE_OPENSSL_MD5)
+#if (NGX_OPENSSL_MD5)
 #define  MD5Init    MD5_Init
 #define  MD5Update  MD5_Update
 #define  MD5Final   MD5_Final
 #endif
 
 
+#if 0
 
 int ngx_http_cache_get_file(ngx_http_request_t *r, ngx_http_cache_ctx_t *ctx)
 {
@@ -237,3 +238,5 @@
 
     return NGX_OK;
 }
+
+#endif
diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c
index bfe5efb..a4e7d80 100644
--- a/src/http/ngx_http_parse.c
+++ b/src/http/ngx_http_parse.c
@@ -686,7 +686,7 @@
 
     ch = *p++;
 
-    while (p < r->uri_start + r->uri.len + 1 && r->args_start == NULL) {
+    while (p < r->uri_end && r->args_start == NULL) {
 
         /*
          * we use "ch = *p++" inside the cycle but this operation is safe
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index a2cf1a0..b6013fc 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -532,6 +532,7 @@
                 r->uri.len = r->uri_end - r->uri_start;
             }
 
+
             if (r->complex_uri || r->quoted_uri) {
 
                 if (!(r->uri.data = ngx_palloc(r->pool, r->uri.len + 1))) {
@@ -557,6 +558,7 @@
                 r->uri.data = r->uri_start;
             }
 
+
             r->unparsed_uri.len = r->uri_end - r->uri_start;
             r->unparsed_uri.data = r->uri_start;
 
@@ -1751,7 +1753,7 @@
 
     ctx = (ngx_http_log_ctx_t *) rev->log->data;
 
-#if (HAVE_KQUEUE)
+#if (NGX_HAVE_KQUEUE)
 
     if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
         if (rev->pending_eof) {
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index 31b1187..141daa1 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -220,7 +220,7 @@
 
         struct {
             ngx_http_cache_hash_t   *hash;
-            ngx_http_cache_t        *cache;
+            ngx_http_cache_entry_t  *cache;
         } cache;
     } data;
 
@@ -254,7 +254,7 @@
     void                    **srv_conf;
     void                    **loc_conf;
 
-    ngx_http_cache_t         *cache;
+    ngx_http_cache_entry_t   *cache;
 
     ngx_file_t                file;