Mercurial > hg > nginx
comparison src/http/modules/ngx_http_event_proxy_handler.c @ 22:aa3b53e74728
nginx-0.0.1-2002-12-05-19:21:24 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 05 Dec 2002 16:21:24 +0000 |
parents | df7fb216a149 |
children | f540a63026c9 |
comparison
equal
deleted
inserted
replaced
21:df7fb216a149 | 22:aa3b53e74728 |
---|---|
15 static int ngx_http_proxy_connect(ngx_http_request_t *r, | 15 static int ngx_http_proxy_connect(ngx_http_request_t *r, |
16 struct sockaddr_in *addr, | 16 struct sockaddr_in *addr, |
17 char *addr_text); | 17 char *addr_text); |
18 static int ngx_http_proxy_send_request(ngx_event_t *ev); | 18 static int ngx_http_proxy_send_request(ngx_event_t *ev); |
19 static int ngx_http_proxy_read_response_header(ngx_event_t *ev); | 19 static int ngx_http_proxy_read_response_header(ngx_event_t *ev); |
20 static int ngx_http_proxy_read_response_body(ngx_event_t *ev); | |
20 | 21 |
21 | 22 |
22 static char conn_close[] = "Connection: close" CRLF; | 23 static char conn_close[] = "Connection: close" CRLF; |
23 | 24 |
24 | 25 |
64 len += sizeof(conn_close) - 1; | 65 len += sizeof(conn_close) - 1; |
65 | 66 |
66 header = (ngx_table_elt_t *) r->headers_in.headers->elts; | 67 header = (ngx_table_elt_t *) r->headers_in.headers->elts; |
67 for (i = 0; i < r->headers_in.headers->nelts; i++) { | 68 for (i = 0; i < r->headers_in.headers->nelts; i++) { |
68 if (&header[i] == r->headers_in.host) | 69 if (&header[i] == r->headers_in.host) |
70 continue; | |
71 | |
72 if (&header[i] == r->headers_in.connection) | |
69 continue; | 73 continue; |
70 | 74 |
71 /* "+ 4" is for ": " and "\r\n" */ | 75 /* "+ 4" is for ": " and "\r\n" */ |
72 len += header[i].key.len + header[i].value.len + 4; | 76 len += header[i].key.len + header[i].value.len + 4; |
73 } | 77 } |
198 pc->servers = c->servers; | 202 pc->servers = c->servers; |
199 | 203 |
200 pc->log = rev->log = wev->log = c->log; | 204 pc->log = rev->log = wev->log = c->log; |
201 | 205 |
202 ngx_test_null(pc->pool, | 206 ngx_test_null(pc->pool, |
203 ngx_create_pool(/* STUB */ 1024 /* */, pc->log), | 207 ngx_create_pool(/* STUB */ 1024 /**/, pc->log), |
204 NGX_ERROR); | 208 NGX_ERROR); |
205 | 209 |
206 wev->event_handler = ngx_http_proxy_send_request; | 210 wev->event_handler = ngx_http_proxy_send_request; |
207 rev->event_handler = ngx_http_proxy_read_response_header; | 211 rev->event_handler = ngx_http_proxy_read_response_header; |
208 | 212 |
238 if (chain == (ngx_chain_t *) -1) | 242 if (chain == (ngx_chain_t *) -1) |
239 return NGX_ERROR; | 243 return NGX_ERROR; |
240 | 244 |
241 p->out = chain; | 245 p->out = chain; |
242 | 246 |
243 return NGX_AGAIN; | 247 return NGX_WAITING; |
244 } | 248 } |
245 | 249 |
246 | 250 |
247 static int ngx_http_proxy_read_response_header(ngx_event_t *ev) | 251 static int ngx_http_proxy_read_response_header(ngx_event_t *ev) |
248 { | 252 { |
261 if (p->header_in == NULL) { | 265 if (p->header_in == NULL) { |
262 ngx_test_null(p->header_in, | 266 ngx_test_null(p->header_in, |
263 ngx_palloc(r->pool, sizeof(ngx_http_proxy_header_in_t)), | 267 ngx_palloc(r->pool, sizeof(ngx_http_proxy_header_in_t)), |
264 NGX_ERROR); | 268 NGX_ERROR); |
265 | 269 |
270 ngx_test_null(p->hunks, | |
271 ngx_create_array(r->pool, | |
272 /* STUB */ 10 /**/, | |
273 sizeof(ngx_hunk_t *)), | |
274 NGX_ERROR); | |
275 | |
276 p->last_hunk = 0; | |
277 | |
266 ngx_test_null(p->hunk, | 278 ngx_test_null(p->hunk, |
267 ngx_create_temp_hunk(r->pool, | 279 ngx_create_temp_hunk(r->pool, |
268 /* STUB */ 1024 /* */, 0, 0), | 280 /* STUB */ 1024 /**/, 0, 0), |
269 NGX_ERROR); | 281 NGX_ERROR); |
282 | |
283 p->hunk->type = NGX_HUNK_MEMORY; | |
270 } | 284 } |
271 | 285 |
272 n = ngx_event_recv(c, p->hunk->last.mem, p->hunk->end - p->hunk->last.mem); | 286 n = ngx_event_recv(c, p->hunk->last.mem, p->hunk->end - p->hunk->last.mem); |
273 | 287 |
274 ngx_log_debug(r->connection->log, "READ:%d" _ n); | 288 ngx_log_debug(c->log, "READ:%d" _ n); |
275 | 289 |
276 p->hunk->last.mem += n; | 290 p->hunk->last.mem += n; |
277 | 291 |
278 *p->hunk->last.mem = '\0'; | 292 *p->hunk->last.mem = '\0'; |
279 ngx_log_debug(r->connection->log, "PROXY:\n'%s'" _ p->hunk->pos.mem); | 293 ngx_log_debug(c->log, "PROXY:\n'%s'" _ p->hunk->pos.mem); |
294 | |
295 ev->event_handler = ngx_http_proxy_read_response_body; | |
296 if (p->hunk->end - p->hunk->last.mem == 0) | |
297 return ngx_http_proxy_read_response_body(ev); | |
280 | 298 |
281 /* STUB */ return NGX_ERROR; | 299 /* STUB */ return NGX_ERROR; |
282 } | 300 } |
283 | 301 |
284 #if 0 | |
285 static int ngx_http_proxy_read_response_body(ngx_event_t *ev) | 302 static int ngx_http_proxy_read_response_body(ngx_event_t *ev) |
286 { | 303 { |
304 int n; | |
305 size_t size; | |
306 ngx_hunk_t *h, **ph; | |
287 ngx_connection_t *c; | 307 ngx_connection_t *c; |
288 ngx_http_request_t *r; | 308 ngx_http_request_t *r; |
289 ngx_http_proxy_ctx_t *p; | 309 ngx_http_proxy_ctx_t *p; |
290 | 310 |
291 if (ev->timedout) | 311 if (ev->timedout) |
293 | 313 |
294 c = (ngx_connection_t *) ev->data; | 314 c = (ngx_connection_t *) ev->data; |
295 r = (ngx_http_request_t *) c->data; | 315 r = (ngx_http_request_t *) c->data; |
296 p = (ngx_http_proxy_ctx_t *) ngx_get_module_ctx(r, ngx_http_proxy_module); | 316 p = (ngx_http_proxy_ctx_t *) ngx_get_module_ctx(r, ngx_http_proxy_module); |
297 | 317 |
298 } | 318 size = 0; |
299 | 319 |
320 if (p->hunks->nelts > 0) { | |
321 h = ((ngx_hunk_t **) p->hunks->elts)[p->hunks->nelts - 1]; | |
322 size = h->end - h->last.mem; | |
323 } | |
324 | |
325 do { | |
326 if (size == 0) { | |
327 ngx_test_null(ph, ngx_push_array(p->hunks), NGX_ERROR); | |
328 ngx_test_null(h, | |
329 ngx_create_temp_hunk(r->pool, | |
330 /* STUB */ 4096 /**/, 0, 0), | |
331 NGX_ERROR); | |
332 | |
333 h->type = NGX_HUNK_MEMORY; | |
334 *ph = h; | |
335 } | |
336 | |
337 n = ngx_event_recv(c, h->last.mem, h->end - h->last.mem); | |
338 | |
339 ngx_log_debug(c->log, "READ:%d" _ n); | |
340 | |
341 h->last.mem += n; | |
342 | |
343 *h->last.mem = '\0'; | |
344 ngx_log_debug(c->log, "PROXY:\n'%s'" _ h->pos.mem); | |
345 size = h->end - h->last.mem; | |
346 | |
347 /* TODO: close if KEVENT and (ev->available == 0 && ev->eof) */ | |
348 | |
349 } while (size == 0); | |
350 | |
351 if (n == 0) { | |
352 return ngx_event_close_connection(ev); | |
353 } | |
354 | |
355 /* STUB */ return NGX_WAITING; | |
356 } | |
357 | |
358 #if 0 | |
300 static int ngx_http_proxy_write_to_client(ngx_event_t *ev) | 359 static int ngx_http_proxy_write_to_client(ngx_event_t *ev) |
301 { | 360 { |
302 /* если бэкенд быстрее, то CLEAR, иначе - ONESHOT */ | 361 /* если бэкенд быстрее, то CLEAR, иначе - ONESHOT */ |
303 | 362 |
304 rc = ngx_http_output_filter(r, h); | 363 rc = ngx_http_output_filter(r, h); |