comparison src/http/modules/proxy/ngx_http_proxy_handler.c @ 163:fb61ba77beba

nginx-0.0.1-2003-10-28-18:45:41 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 28 Oct 2003 15:45:41 +0000
parents 96993d4d5067
children 84036764e215
comparison
equal deleted inserted replaced
162:96993d4d5067 163:fb61ba77beba
106 {ngx_string("proxy_temp_file_write_size"), 106 {ngx_string("proxy_temp_file_write_size"),
107 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 107 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
108 ngx_conf_set_size_slot, 108 ngx_conf_set_size_slot,
109 NGX_HTTP_LOC_CONF_OFFSET, 109 NGX_HTTP_LOC_CONF_OFFSET,
110 offsetof(ngx_http_proxy_loc_conf_t, temp_file_write_size), 110 offsetof(ngx_http_proxy_loc_conf_t, temp_file_write_size),
111 NULL},
112
113 {ngx_string("proxy_pass_server"),
114 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
115 ngx_conf_set_flag_slot,
116 NGX_HTTP_LOC_CONF_OFFSET,
117 offsetof(ngx_http_proxy_loc_conf_t, pass_server),
111 NULL}, 118 NULL},
112 119
113 ngx_null_command 120 ngx_null_command
114 }; 121 };
115 122
235 242
236 if (r->connection->read->timer_set) { 243 if (r->connection->read->timer_set) {
237 ngx_del_timer(r->connection->read); 244 ngx_del_timer(r->connection->read);
238 } 245 }
239 246
240 ngx_is_null(cl, ngx_http_proxy_create_request(p)) { 247 if (!(cl = ngx_http_proxy_create_request(p))) {
241 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); 248 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
242 return; 249 return;
243 } 250 }
244
245 #if 0
246 cl = ngx_http_proxy_create_request(p);
247 if (cl == NULL) {
248 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
249 return;
250 }
251 #endif
252 251
253 if (r->request_hunks) { 252 if (r->request_hunks) {
254 cl->next = r->request_hunks; 253 cl->next = r->request_hunks;
255 } 254 }
256 255
264 p->action = "connecting to upstream"; 263 p->action = "connecting to upstream";
265 264
266 out_ctx = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t)); 265 out_ctx = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t));
267 if (out_ctx == NULL) { 266 if (out_ctx == NULL) {
268 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); 267 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
268 return;
269 } 269 }
270 270
271 p->output_chain_ctx = out_ctx; 271 p->output_chain_ctx = out_ctx;
272 272
273 if (r->request_body_hunk) { 273 if (r->request_body_hunk) {
286 out_ctx->output_filter = (ngx_output_chain_filter_pt) ngx_chain_write; 286 out_ctx->output_filter = (ngx_output_chain_filter_pt) ngx_chain_write;
287 287
288 write_ctx = ngx_pcalloc(r->pool, sizeof(ngx_chain_write_ctx_t)); 288 write_ctx = ngx_pcalloc(r->pool, sizeof(ngx_chain_write_ctx_t));
289 if (write_ctx == NULL) { 289 if (write_ctx == NULL) {
290 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); 290 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
291 return;
291 } 292 }
292 293
293 out_ctx->output_ctx = write_ctx; 294 out_ctx->output_ctx = write_ctx;
294 write_ctx->pool = r->pool; 295 write_ctx->pool = r->pool;
295 write_ctx->last = &write_ctx->out; 296 write_ctx->last = &write_ctx->out;
765 766
766 ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_HTTP_HEADER); 767 ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_HTTP_HEADER);
767 return; 768 return;
768 } 769 }
769 770
770 /* NGX_AGAIN: a header line parsing is still not complete */ 771 /* rc == NGX_AGAIN: a header line parsing is still not complete */
771 772
772 if (p->header_in->last == p->header_in->end) { 773 if (p->header_in->last == p->header_in->end) {
773 ngx_log_error(NGX_LOG_ERR, rev->log, 0, 774 ngx_log_error(NGX_LOG_ERR, rev->log, 0,
774 "upstream sent too big header"); 775 "upstream sent too big header");
775 776
833 ngx_event_pipe_t *ep; 834 ngx_event_pipe_t *ep;
834 ngx_http_request_t *r; 835 ngx_http_request_t *r;
835 836
836 r = p->request; 837 r = p->request;
837 838
839 r->headers_out.status = p->status;
840
838 r->headers_out.content_length_n = -1; 841 r->headers_out.content_length_n = -1;
839 r->headers_out.content_length = NULL; 842 r->headers_out.content_length = NULL;
840 843
841 /* copy an upstream header to r->headers_out */ 844 /* copy an upstream header to r->headers_out */
842 845
850 if (p->accel) { 853 if (p->accel) {
851 if (&ph[i] == p->headers_in.date 854 if (&ph[i] == p->headers_in.date
852 || &ph[i] == p->headers_in.accept_ranges) { 855 || &ph[i] == p->headers_in.accept_ranges) {
853 continue; 856 continue;
854 } 857 }
858
859 if (&ph[i] == p->headers_in.server && !p->lcf->pass_server) {
860 continue;
861 }
862 }
863
864 if (&ph[i] == p->headers_in.content_type) {
865 r->headers_out.content_type = &ph[i];
866 r->headers_out.content_type->key.len = 0;
867 continue;
855 } 868 }
856 869
857 ch = ngx_push_table(r->headers_out.headers); 870 ch = ngx_push_table(r->headers_out.headers);
858 if (ch == NULL) { 871 if (ch == NULL) {
859 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR); 872 ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
860 return; 873 return;
861 } 874 }
862 875
863 *ch = ph[i]; 876 *ch = ph[i];
864 877
865 if (&ph[i] == p->headers_in.content_type) { 878 /*
866 r->headers_out.content_type = ch; 879 * ngx_http_header_filter() output the following headers
867 r->headers_out.content_type->key.len = 0; 880 * from r->headers_out.headers if they are set:
881 * r->headers_out.server,
882 * r->headers_out.date,
883 * r->headers_out.content_length
884 */
885
886 if (&ph[i] == p->headers_in.server) {
887 r->headers_out.server = ch;
868 continue; 888 continue;
869 } 889 }
870 890
891 if (&ph[i] == p->headers_in.date) {
892 r->headers_out.date = ch;
893 continue;
894 }
895
871 if (&ph[i] == p->headers_in.content_length) { 896 if (&ph[i] == p->headers_in.content_length) {
897
872 r->headers_out.content_length_n = 898 r->headers_out.content_length_n =
873 ngx_atoi(p->headers_in.content_length->value.data, 899 ngx_atoi(p->headers_in.content_length->value.data,
874 p->headers_in.content_length->value.len); 900 p->headers_in.content_length->value.len);
875 r->headers_out.content_length = ch; 901 r->headers_out.content_length = ch;
876 continue; 902 continue;
877 } 903 }
878 } 904 }
879 905
880 /* STUB */
881
882 if (p->headers_in.server) {
883 r->headers_out.server = p->headers_in.server;
884 }
885
886 if (!p->accel && p->headers_in.date) {
887 r->headers_out.date = p->headers_in.date;
888 }
889
890 /* */
891
892 906
893 /* TODO: preallocate event_pipe hunks, look "Content-Length" */ 907 /* TODO: preallocate event_pipe hunks, look "Content-Length" */
894
895 r->headers_out.status = p->status;
896 908
897 rc = ngx_http_send_header(r); 909 rc = ngx_http_send_header(r);
898 910
899 p->header_sent = 1; 911 p->header_sent = 1;
900 912
1411 /* "proxy_cyclic_temp_file" is disabled */ 1423 /* "proxy_cyclic_temp_file" is disabled */
1412 conf->cyclic_temp_file = 0; 1424 conf->cyclic_temp_file = 0;
1413 1425
1414 conf->next_upstream = NGX_CONF_UNSET; 1426 conf->next_upstream = NGX_CONF_UNSET;
1415 1427
1428 conf->pass_server = NGX_CONF_UNSET;
1429
1416 return conf; 1430 return conf;
1417 } 1431 }
1418 1432
1419 1433
1420 static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, 1434 static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf,
1449 (NGX_HTTP_PROXY_FT_ERROR|NGX_HTTP_PROXY_FT_TIMEOUT)); 1463 (NGX_HTTP_PROXY_FT_ERROR|NGX_HTTP_PROXY_FT_TIMEOUT));
1450 1464
1451 ngx_conf_merge_path_value(conf->temp_path, prev->temp_path, 1465 ngx_conf_merge_path_value(conf->temp_path, prev->temp_path,
1452 "temp", 1, 2, 0, cf->pool); 1466 "temp", 1, 2, 0, cf->pool);
1453 1467
1468 ngx_conf_merge_value(conf->pass_server, prev->pass_server, 0);
1469
1454 return NULL; 1470 return NULL;
1455 } 1471 }
1456 1472
1457 1473
1458 1474