diff src/http/modules/proxy/ngx_http_event_proxy_handler.c @ 82:fccdb921e8b8

nginx-0.0.1-2003-04-25-18:43:13 import
author Igor Sysoev <igor@sysoev.ru>
date Fri, 25 Apr 2003 14:43:13 +0000
parents b2ece31c976a
children a7e45c45a95c
line wrap: on
line diff
--- a/src/http/modules/proxy/ngx_http_event_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_event_proxy_handler.c
@@ -24,6 +24,7 @@ typedef struct {
 
 static int ngx_http_proxy_handler(ngx_http_request_t *r);
 
+static int ngx_http_proxy_read_client_body(ngx_http_proxy_ctx_t *p);
 static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p);
 static int ngx_http_proxy_process_upstream(ngx_http_proxy_ctx_t *p,
                                            ngx_event_t *ev);
@@ -182,7 +183,11 @@ static int ngx_http_proxy_handler(ngx_ht
     p->method = r->method;
     p->headers_in.headers = ngx_create_table(r->pool, 10);
 
-    /* TODO: read a client's body */
+    if (r->headers_in.content_length_n > 0) {
+        if (ngx_http_proxy_read_client_body(p) == NGX_ERROR) {
+            return NGX_HTTP_INTERNAL_SERVER_ERROR;
+        }
+    }
 
     chain = ngx_http_proxy_create_request(p);
     if (chain == NULL) {
@@ -204,6 +209,53 @@ static int ngx_http_proxy_handler(ngx_ht
 }
 
 
+static int ngx_http_proxy_read_client_body(ngx_http_proxy_ctx_t *p)
+{
+    int                  size, first_part;
+    ngx_hunk_t          *h;
+    ngx_http_request_t  *r;
+
+    r = p->request;
+
+    first_part = r->header_in->last - r->header_in->pos;
+
+    if (first_part > r->headers_in.content_length_n) {
+        first_part = r->headers_in.content_length_n;
+        size = 0;
+
+    } else {
+        size = r->headers_in.content_length_n - first_part;
+        if (size > p->lcf->client_request_buffer_size) {
+            size = p->lcf->client_request_buffer_size;
+
+        } else if (size > NGX_PAGE_SIZE) {
+            size = ((size + NGX_PAGE_SIZE) / NGX_PAGE_SIZE) * NGX_PAGE_SIZE;
+        }
+
+        if (size) {
+            ngx_test_null(p->client_request_hunk, ngx_palloc(r->pool, size),
+                          NGX_ERROR);
+        }
+    }
+
+    if (first_part) {
+        ngx_test_null(h, ngx_alloc_hunk(r->pool), NGX_ERROR);
+
+        h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP;
+        h->pos = h->start = h->pre_start = r->header_in->pos;
+        h->last = h->end = h->post_end = r->header_in->pos + first_part;
+        h->file_pos = h->file_last = 0;
+        h->file = NULL;
+        h->shadow = NULL;
+        h->tag = 0;
+
+        p->client_first_part_hunk = h;
+    }
+
+    return NGX_OK;
+}
+
+
 static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
 {
     int                  i;