comparison src/http/modules/ngx_http_chunked_filter.c @ 343:6bdf858bff8c

nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
author Igor Sysoev <igor@sysoev.ru>
date Fri, 28 May 2004 15:49:23 +0000
parents 4feff829a849
children 2e3cbc1bbe3c
comparison
equal deleted inserted replaced
342:0ee0642af5f1 343:6bdf858bff8c
56 56
57 static int ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in) 57 static int ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
58 { 58 {
59 u_char *chunk; 59 u_char *chunk;
60 size_t size, len; 60 size_t size, len;
61 ngx_hunk_t *h; 61 ngx_buf_t *b;
62 ngx_chain_t out, tail, *cl, *tl, **ll; 62 ngx_chain_t out, tail, *cl, *tl, **ll;
63 63
64 if (in == NULL || !r->chunked) { 64 if (in == NULL || !r->chunked) {
65 return ngx_http_next_body_filter(r, in); 65 return ngx_http_next_body_filter(r, in);
66 } 66 }
67 67
68 out.hunk = NULL; 68 out.buf = NULL;
69 ll = &out.next; 69 ll = &out.next;
70 70
71 size = 0; 71 size = 0;
72 cl = in; 72 cl = in;
73 73
74 for ( ;; ) { 74 for ( ;; ) {
75 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 75 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
76 "http chunk: %d", ngx_hunk_size(cl->hunk)); 76 "http chunk: %d", ngx_buf_size(cl->buf));
77 77
78 size += ngx_hunk_size(cl->hunk); 78 size += ngx_buf_size(cl->buf);
79 79
80 ngx_test_null(tl, ngx_alloc_chain_link(r->pool), NGX_ERROR); 80 ngx_test_null(tl, ngx_alloc_chain_link(r->pool), NGX_ERROR);
81 tl->hunk = cl->hunk; 81 tl->buf = cl->buf;
82 *ll = tl; 82 *ll = tl;
83 ll = &tl->next; 83 ll = &tl->next;
84 84
85 if (cl->next == NULL) { 85 if (cl->next == NULL) {
86 break; 86 break;
91 91
92 if (size) { 92 if (size) {
93 ngx_test_null(chunk, ngx_palloc(r->pool, 11), NGX_ERROR); 93 ngx_test_null(chunk, ngx_palloc(r->pool, 11), NGX_ERROR);
94 len = ngx_snprintf((char *) chunk, 11, SIZE_T_X_FMT CRLF, size); 94 len = ngx_snprintf((char *) chunk, 11, SIZE_T_X_FMT CRLF, size);
95 95
96 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); 96 ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR);
97 h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; 97 b->temporary = 1;
98 h->pos = chunk; 98 b->pos = chunk;
99 h->last = chunk + len; 99 b->last = chunk + len;
100 100
101 out.hunk = h; 101 out.buf = b;
102 } 102 }
103 103
104 if (cl->hunk->type & NGX_HUNK_LAST) { 104 if (cl->buf->last_buf) {
105 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); 105 ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR);
106 h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY|NGX_HUNK_LAST; 106 b->memory = 1;
107 h->pos = (u_char *) CRLF "0" CRLF CRLF; 107 b->last_buf = 1;
108 h->last = h->pos + 7; 108 b->pos = (u_char *) CRLF "0" CRLF CRLF;
109 b->last = b->pos + 7;
109 110
110 cl->hunk->type &= ~NGX_HUNK_LAST; 111 cl->buf->last_buf = 0;
111 112
112 if (size == 0) { 113 if (size == 0) {
113 h->pos += 2; 114 b->pos += 2;
114 out.hunk = h; 115 out.buf = b;
115 out.next = NULL; 116 out.next = NULL;
116 117
117 return ngx_http_next_body_filter(r, &out); 118 return ngx_http_next_body_filter(r, &out);
118 } 119 }
119 120
121 if (size == 0) { 122 if (size == 0) {
122 *ll = NULL; 123 *ll = NULL;
123 return ngx_http_next_body_filter(r, out.next); 124 return ngx_http_next_body_filter(r, out.next);
124 } 125 }
125 126
126 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); 127 ngx_test_null(b, ngx_calloc_buf(r->pool), NGX_ERROR);
127 h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY; 128 b->memory = 1;
128 h->pos = (u_char *) CRLF; 129 b->pos = (u_char *) CRLF;
129 h->last = h->pos + 2; 130 b->last = b->pos + 2;
130 } 131 }
131 132
132 tail.hunk = h; 133 tail.buf = b;
133 tail.next = NULL; 134 tail.next = NULL;
134 *ll = &tail; 135 *ll = &tail;
135 136
136 return ngx_http_next_body_filter(r, &out); 137 return ngx_http_next_body_filter(r, &out);
137 } 138 }