Mercurial > hg > nginx-quic
comparison src/http/ngx_http_request_body.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 | |
children | a7e45c45a95c |
comparison
equal
deleted
inserted
replaced
81:b2ece31c976a | 82:fccdb921e8b8 |
---|---|
1 | |
2 | |
3 | |
4 | |
5 int ngx_http_start_read_client_body(ngx_http_proxy_ctx_t *p) | |
6 { | |
7 int first_part, size; | |
8 ngx_hunk_t *h; | |
9 ngx_http_request_t *r; | |
10 | |
11 r = p->request; | |
12 | |
13 first_part = r->header_in->last - r->header_in->pos; | |
14 | |
15 if (first_part > r->headers_in.content_length_n) { | |
16 first_part = r->headers_in.content_length_n; | |
17 size = 0; | |
18 | |
19 } else { | |
20 size = r->headers_in.content_length_n - first_part; | |
21 if (size > p->lcf->client_request_buffer_size) { | |
22 size = p->lcf->client_request_buffer_size; | |
23 | |
24 } else if (size > NGX_PAGE_SIZE) { | |
25 size = ((size + NGX_PAGE_SIZE) / NGX_PAGE_SIZE) * NGX_PAGE_SIZE; | |
26 } | |
27 | |
28 if (size) { | |
29 ngx_test_null(p->client_request_hunk, ngx_palloc(r->pool, size), | |
30 NGX_ERROR); | |
31 } | |
32 } | |
33 | |
34 if (first_part) { | |
35 ngx_test_null(h, ngx_alloc_hunk(r->pool), NGX_ERROR); | |
36 | |
37 h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; | |
38 h->pos = h->start = h->pre_start = r->header_in->pos; | |
39 h->last = h->end = h->post_end = r->header_in->pos + first_part; | |
40 h->file_pos = h->file_last = 0; | |
41 h->file = NULL; | |
42 h->shadow = NULL; | |
43 h->tag = 0; | |
44 | |
45 p->client_first_part_hunk = h; | |
46 } | |
47 | |
48 return NGX_OK; | |
49 } | |
50 | |
51 | |
52 int ngx_http_read_client_body(ngx_event_t *rev) | |
53 { | |
54 | |
55 do { | |
56 if (r->header_in->last < r->header_in->end) { | |
57 rb->chain[0].hunk = r->header_in; | |
58 | |
59 if (rb->hunk) { | |
60 rb->chain[0].next = &rb->chain[1]; | |
61 rb->chain[1].hunk = rb->hunk; | |
62 rb->chain[1].next = NULL; | |
63 | |
64 } else { | |
65 rb->chain[0].next = NULL; | |
66 } | |
67 | |
68 } else { | |
69 rb->chain[0].hunk = rb->hunk; | |
70 rb->chain[0].next = NULL; | |
71 } | |
72 | |
73 n = ngx_recv_chain(c, &rb->chain); | |
74 | |
75 if (n == NGX_ERROR) { | |
76 return NGX_ERROR; | |
77 } | |
78 | |
79 if (n == NGX_AGAIN) { | |
80 return NGX_AGAIN; | |
81 } | |
82 | |
83 for (entry = &rb->chain; entry; entry = entry->next) { | |
84 size = entry->hunk->end - entry->hunk->last; | |
85 | |
86 if (n >= size) { | |
87 n -= size; | |
88 entry->hunk->last = entry->hunk->end; | |
89 | |
90 continue; | |
91 } | |
92 | |
93 entry->hunk->last += n; | |
94 | |
95 break; | |
96 } | |
97 | |
98 if (rb->hunk && rb->hunk->last == rb->hunk->end) { | |
99 if (rb->temp_file->fd == NGX_INVALID_FILE) { | |
100 rc = ngx_create_temp_file(rb->temp_file, rb->temp_path, r->pool, | |
101 rb->number, rb->random, 0); | |
102 | |
103 if (rc == NGX_ERROR) { | |
104 return NGX_ERROR; | |
105 } | |
106 | |
107 if (rc == NGX_AGAIN) { | |
108 return NGX_AGAIN; | |
109 } | |
110 } | |
111 | |
112 n = ngx_write_file(rb->temp_file, rb->hunk, | |
113 rb->hunk->last - rb->hunk->pos, rb->offset); | |
114 | |
115 if (rc == NGX_ERROR) { | |
116 return NGX_ERROR; | |
117 } | |
118 | |
119 rb->offset += n; | |
120 rb->hunk->last = rb->hunk->pos; | |
121 } | |
122 | |
123 } while (rev->ready); | |
124 | |
125 return NGX_OK; | |
126 } | |
127 | |
128 | |
129 int ngx_init_client_request_body_chain(ngx_http_reuqest_t *r) | |
130 { | |
131 int i; | |
132 ngx_hunk_t *h; | |
133 ngx_http_request_body_t *rb; | |
134 | |
135 rb = r->request_body; | |
136 | |
137 rb->chain[0].hunk = rb->header_out; | |
138 i = 0; | |
139 | |
140 if (r->header_in->pos < r->header_in->last) { | |
141 rb->chain[i].next = &rb->chain[i + 1]; | |
142 i++; | |
143 rb->chain[i].hunk = r->header_in; | |
144 } | |
145 | |
146 if (rb->temp_file->fd != NGX_INVALID_FILE) { | |
147 if (rb->file_hunk == NULL) { | |
148 ngx_test_null(h, ngx_alloc_hunk(r->pool), NGX_ERROR); | |
149 | |
150 h->type = NGX_HUNK_FILE; | |
151 h->pos = h->start = h->pre_start = 0; | |
152 h->last = h->end = h->post_end = 0; | |
153 h->file_pos = 0; | |
154 h->file_last = rb->offset; | |
155 h->file = rb->temp_file; | |
156 h->shadow = NULL; | |
157 h->tag = 0; | |
158 | |
159 rb->file_hunk = h; | |
160 } | |
161 | |
162 rb->chain[i].next = &rb->chain[i + 1]; | |
163 i++; | |
164 rb->chain[i].hunk = rb->file_hunk; | |
165 } | |
166 | |
167 if (rb->hunk && rb->hunk->pos < rb->hunk->last) { | |
168 rb->chain[i].next = &rb->chain[i + 1]; | |
169 i++; | |
170 rb->chain[i].hunk = h; | |
171 } | |
172 | |
173 rb->chain[i].next = NULL; | |
174 | |
175 return NGX_OK; | |
176 } | |
177 | |
178 | |
179 int ngx_reinit_client_request_body_hunks(ngx_http_reuqest_t *r) | |
180 { | |
181 ngx_http_request_body_t *rb; | |
182 | |
183 rb = r->request_body; | |
184 | |
185 if (rb->header_in_pos) { | |
186 r->header_in->pos = rb->header_in_pos; | |
187 } | |
188 | |
189 if (rb->file_hunk) { | |
190 rb->file_hunk->file_pos = rb->file_hunk->file_start; | |
191 } | |
192 | |
193 if (rb->hunk) { | |
194 rb->hunk->pos = rb->hunk->start; | |
195 } | |
196 } |