Mercurial > hg > nginx-quic
comparison src/http/modules/proxy/ngx_http_proxy_handler.c @ 177:4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 10 Nov 2003 17:17:31 +0000 |
parents | c0552e5ab567 |
children | a8ff48d26cca |
comparison
equal
deleted
inserted
replaced
176:c0552e5ab567 | 177:4db54fdbcbe7 |
---|---|
5 #include <ngx_http_proxy_handler.h> | 5 #include <ngx_http_proxy_handler.h> |
6 | 6 |
7 | 7 |
8 static int ngx_http_proxy_handler(ngx_http_request_t *r); | 8 static int ngx_http_proxy_handler(ngx_http_request_t *r); |
9 | 9 |
10 static int ngx_http_proxy_init(ngx_cycle_t *cycle); | 10 static char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, char *buf, |
11 uintptr_t data); | |
12 static char *ngx_http_proxy_log_cache_state(ngx_http_request_t *r, char *buf, | |
13 uintptr_t data); | |
14 static char *ngx_http_proxy_log_reason(ngx_http_request_t *r, char *buf, | |
15 uintptr_t data); | |
16 | |
17 static int ngx_http_proxy_pre_conf(ngx_conf_t *cf); | |
11 static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf); | 18 static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf); |
12 static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, | 19 static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, |
13 void *parent, void *child); | 20 void *parent, void *child); |
14 | 21 |
15 static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, | 22 static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, |
192 ngx_null_command | 199 ngx_null_command |
193 }; | 200 }; |
194 | 201 |
195 | 202 |
196 ngx_http_module_t ngx_http_proxy_module_ctx = { | 203 ngx_http_module_t ngx_http_proxy_module_ctx = { |
204 ngx_http_proxy_pre_conf, /* pre conf */ | |
205 | |
197 NULL, /* create main configuration */ | 206 NULL, /* create main configuration */ |
198 NULL, /* init main configuration */ | 207 NULL, /* init main configuration */ |
199 | 208 |
200 NULL, /* create server configuration */ | 209 NULL, /* create server configuration */ |
201 NULL, /* merge server configuration */ | 210 NULL, /* merge server configuration */ |
211 ngx_http_proxy_commands, /* module directives */ | 220 ngx_http_proxy_commands, /* module directives */ |
212 NGX_HTTP_MODULE, /* module type */ | 221 NGX_HTTP_MODULE, /* module type */ |
213 NULL, /* init module */ | 222 NULL, /* init module */ |
214 NULL /* init child */ | 223 NULL /* init child */ |
215 }; | 224 }; |
225 | |
226 | |
227 | |
228 static ngx_http_log_op_name_t ngx_http_proxy_log_fmt_ops[] = { | |
229 { ngx_string("proxy"), /* STUB */ 100, | |
230 ngx_http_proxy_log_proxy_state }, | |
231 { ngx_string("proxy_cache_state"), sizeof("BYPASS") - 1, | |
232 ngx_http_proxy_log_cache_state }, | |
233 { ngx_string("proxy_reason"), sizeof("BPS") - 1, | |
234 ngx_http_proxy_log_reason }, | |
235 { ngx_null_string, 0, NULL } | |
236 }; | |
237 | |
216 | 238 |
217 | 239 |
218 ngx_http_header_t ngx_http_proxy_headers_in[] = { | 240 ngx_http_header_t ngx_http_proxy_headers_in[] = { |
219 { ngx_string("Date"), offsetof(ngx_http_proxy_headers_in_t, date) }, | 241 { ngx_string("Date"), offsetof(ngx_http_proxy_headers_in_t, date) }, |
220 { ngx_string("Server"), offsetof(ngx_http_proxy_headers_in_t, server) }, | 242 { ngx_string("Server"), offsetof(ngx_http_proxy_headers_in_t, server) }, |
250 ngx_string("AGED"), | 272 ngx_string("AGED"), |
251 ngx_string("HIT") | 273 ngx_string("HIT") |
252 }; | 274 }; |
253 | 275 |
254 | 276 |
255 static ngx_str_t cache_reason[] = { | 277 static ngx_str_t cache_reasons[] = { |
256 ngx_string("BPS"), | 278 ngx_string("BPS"), |
257 ngx_string("XAE"), | 279 ngx_string("XAE"), |
258 ngx_string("CTL"), | 280 ngx_string("CTL"), |
259 ngx_string("EXP"), | 281 ngx_string("EXP"), |
260 ngx_string("MVD"), | 282 ngx_string("MVD"), |
448 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_socket_errno, | 470 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_socket_errno, |
449 ngx_close_socket_n " failed"); | 471 ngx_close_socket_n " failed"); |
450 } | 472 } |
451 | 473 |
452 c->fd = -1; | 474 c->fd = -1; |
453 } | |
454 | |
455 | |
456 size_t ngx_http_proxy_log_state(void *data, char *buf, size_t len) | |
457 { | |
458 return 0; | |
459 } | 475 } |
460 | 476 |
461 | 477 |
462 size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len) | 478 size_t ngx_http_proxy_log_error(void *data, char *buf, size_t len) |
463 { | 479 { |
477 peer->peers->peers[peer->cur_peer].addr_port_text.data, | 493 peer->peers->peers[peer->cur_peer].addr_port_text.data, |
478 p->lcf->upstream->uri.data, | 494 p->lcf->upstream->uri.data, |
479 r->uri.data + p->lcf->upstream->location->len, | 495 r->uri.data + p->lcf->upstream->location->len, |
480 r->args.len ? "?" : "", | 496 r->args.len ? "?" : "", |
481 r->args.len ? r->args.data : ""); | 497 r->args.len ? r->args.data : ""); |
498 } | |
499 | |
500 | |
501 static char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, char *buf, | |
502 uintptr_t data) | |
503 { | |
504 ngx_http_proxy_ctx_t *p; | |
505 | |
506 p = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
507 | |
508 if (p == NULL) { | |
509 *buf = '-'; | |
510 return buf + 1; | |
511 } | |
512 | |
513 if (p->state->cache_state == 0) { | |
514 *buf++ = '-'; | |
515 | |
516 } else { | |
517 buf = ngx_cpymem(buf, cache_states[p->state->cache_state - 1].data, | |
518 cache_states[p->state->cache_state - 1].len); | |
519 } | |
520 | |
521 *buf++ = '/'; | |
522 | |
523 *buf++ = 'X'; | |
524 | |
525 *buf++ = '/'; | |
526 | |
527 *buf++ = 'X'; | |
528 | |
529 *buf++ = ' '; | |
530 | |
531 if (p->state->status == 0) { | |
532 *buf++ = '-'; | |
533 | |
534 } else { | |
535 buf += ngx_snprintf(buf, 4, "%d", p->state->status); | |
536 } | |
537 | |
538 *buf++ = '/'; | |
539 | |
540 if (p->state->reason == 0) { | |
541 *buf++ = '-'; | |
542 | |
543 } else { | |
544 buf = ngx_cpymem(buf, cache_reasons[p->state->reason - 1].data, | |
545 cache_reasons[p->state->reason - 1].len); | |
546 } | |
547 | |
548 *buf++ = '/'; | |
549 | |
550 if (p->state->reason >= NGX_HTTP_PROXY_CACHE_XAE) { | |
551 *buf++ = '-'; | |
552 | |
553 } else { | |
554 buf += ngx_snprintf(buf, NGX_TIME_LEN, TIME_FMT, p->state->expires); | |
555 } | |
556 | |
557 return buf; | |
558 } | |
559 | |
560 | |
561 static char *ngx_http_proxy_log_cache_state(ngx_http_request_t *r, char *buf, | |
562 uintptr_t data) | |
563 { | |
564 ngx_http_proxy_ctx_t *p; | |
565 | |
566 p = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
567 | |
568 if (p == NULL || p->state->cache_state == 0) { | |
569 *buf = '-'; | |
570 return buf + 1; | |
571 } | |
572 | |
573 return ngx_cpymem(buf, cache_states[p->state->cache_state - 1].data, | |
574 cache_states[p->state->cache_state - 1].len); | |
575 } | |
576 | |
577 | |
578 static char *ngx_http_proxy_log_reason(ngx_http_request_t *r, char *buf, | |
579 uintptr_t data) | |
580 { | |
581 ngx_http_proxy_ctx_t *p; | |
582 | |
583 p = ngx_http_get_module_ctx(r, ngx_http_proxy_module); | |
584 | |
585 if (p == NULL || p->state->reason == 0) { | |
586 *buf = '-'; | |
587 return buf + 1; | |
588 } | |
589 | |
590 return ngx_cpymem(buf, cache_reasons[p->state->reason - 1].data, | |
591 cache_reasons[p->state->reason - 1].len); | |
592 } | |
593 | |
594 | |
595 static int ngx_http_proxy_pre_conf(ngx_conf_t *cf) | |
596 { | |
597 ngx_http_log_op_name_t *op; | |
598 | |
599 for (op = ngx_http_proxy_log_fmt_ops; op->name.len; op++) { /* void */ } | |
600 op->op = NULL; | |
601 | |
602 op = ngx_http_log_fmt_ops; | |
603 | |
604 for (op = ngx_http_log_fmt_ops; op->op; op++) { | |
605 if (op->name.len == 0) { | |
606 op = (ngx_http_log_op_name_t *) op->op; | |
607 } | |
608 } | |
609 | |
610 op->op = (ngx_http_log_op_pt) ngx_http_proxy_log_fmt_ops; | |
611 | |
612 return NGX_OK; | |
482 } | 613 } |
483 | 614 |
484 | 615 |
485 static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf) | 616 static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf) |
486 { | 617 { |