Mercurial > hg > nginx
comparison src/http/modules/ngx_http_chunked_filter.c @ 337:4feff829a849
nginx-0.0.3-2004-05-19-00:28:54 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 18 May 2004 20:28:54 +0000 |
parents | ca9a7f8c86da |
children | 6bdf858bff8c |
comparison
equal
deleted
inserted
replaced
336:ca9a7f8c86da | 337:4feff829a849 |
---|---|
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_hunk_t *h; |
62 ngx_chain_t *out, *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 ngx_test_null(out, ngx_alloc_chain_link(r->pool), NGX_ERROR); | 68 out.hunk = NULL; |
69 out->hunk = NULL; | 69 ll = &out.next; |
70 ll = &out->next; | |
71 | 70 |
72 size = 0; | 71 size = 0; |
73 cl = in; | 72 cl = in; |
74 | 73 |
75 for ( ;; ) { | 74 for ( ;; ) { |
97 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); | 96 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); |
98 h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; | 97 h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; |
99 h->pos = chunk; | 98 h->pos = chunk; |
100 h->last = chunk + len; | 99 h->last = chunk + len; |
101 | 100 |
102 out->hunk = h; | 101 out.hunk = h; |
103 } | 102 } |
104 | 103 |
105 if (cl->hunk->type & NGX_HUNK_LAST) { | 104 if (cl->hunk->type & NGX_HUNK_LAST) { |
106 | |
107 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); | 105 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); |
108 h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY|NGX_HUNK_LAST; | 106 h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY|NGX_HUNK_LAST; |
109 h->pos = (u_char *) CRLF "0" CRLF CRLF; | 107 h->pos = (u_char *) CRLF "0" CRLF CRLF; |
110 h->last = h->pos + 7; | 108 h->last = h->pos + 7; |
111 | 109 |
112 cl->hunk->type &= ~NGX_HUNK_LAST; | 110 cl->hunk->type &= ~NGX_HUNK_LAST; |
113 | 111 |
114 if (size == 0) { | 112 if (size == 0) { |
115 out->hunk = h; | 113 h->pos += 2; |
116 out->next = NULL; | 114 out.hunk = h; |
115 out.next = NULL; | |
117 | 116 |
118 return ngx_http_next_body_filter(r, out); | 117 return ngx_http_next_body_filter(r, &out); |
119 } | 118 } |
120 | 119 |
121 } else { | 120 } else { |
122 if (size == 0) { | 121 if (size == 0) { |
123 *ll = NULL; | 122 *ll = NULL; |
124 return ngx_http_next_body_filter(r, out->next); | 123 return ngx_http_next_body_filter(r, out.next); |
125 } | 124 } |
126 | 125 |
127 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); | 126 ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR); |
128 h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY; | 127 h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY; |
129 h->pos = (u_char *) CRLF; | 128 h->pos = (u_char *) CRLF; |
130 h->last = h->pos + 2; | 129 h->last = h->pos + 2; |
131 } | 130 } |
132 | 131 |
133 ngx_alloc_link_and_set_hunk(tl, h, r->pool, NGX_ERROR); | 132 tail.hunk = h; |
134 *ll = tl; | 133 tail.next = NULL; |
134 *ll = &tail; | |
135 | 135 |
136 return ngx_http_next_body_filter(r, out); | 136 return ngx_http_next_body_filter(r, &out); |
137 } | 137 } |
138 | 138 |
139 | 139 |
140 static int ngx_http_chunked_filter_init(ngx_cycle_t *cycle) | 140 static int ngx_http_chunked_filter_init(ngx_cycle_t *cycle) |
141 { | 141 { |