comparison src/http/modules/proxy/ngx_http_proxy_handler.c @ 452:23fb87bddda1 release-0.1.1

nginx-0.1.1-RELEASE import *) Feature: the gzip_types directive. *) Feature: the tcp_nodelay directive. *) Feature: the send_lowat directive is working not only on OSes that support kqueue NOTE_LOWAT, but also on OSes that support SO_SNDLOWAT. *) Feature: the setproctitle() emulation for Linux and Solaris. *) Bugfix: the "Location" header rewrite bug fixed while the proxying. *) Bugfix: the ngx_http_chunked_module module may get caught in an endless loop. *) Bugfix: the /dev/poll module bugs fixed. *) Bugfix: the responses were corrupted when the temporary files were used while the proxying. *) Bugfix: the unescaped requests were passed to the backend. *) Bugfix: while the build configuration on Linux 2.4 the --with-poll_module parameter was required.
author Igor Sysoev <igor@sysoev.ru>
date Mon, 11 Oct 2004 15:07:03 +0000
parents 241dc8092a33
children 295d97d70c69
comparison
equal deleted inserted replaced
451:f40362e47689 452:23fb87bddda1
26 26
27 static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, 27 static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
28 void *conf); 28 void *conf);
29 static char *ngx_http_proxy_parse_upstream(ngx_str_t *url, 29 static char *ngx_http_proxy_parse_upstream(ngx_str_t *url,
30 ngx_http_proxy_upstream_conf_t *u); 30 ngx_http_proxy_upstream_conf_t *u);
31
32 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data);
33
34 static ngx_conf_post_t ngx_http_proxy_lowat_post =
35 { ngx_http_proxy_lowat_check } ;
31 36
32 37
33 static ngx_conf_bitmask_t next_upstream_masks[] = { 38 static ngx_conf_bitmask_t next_upstream_masks[] = {
34 { ngx_string("error"), NGX_HTTP_PROXY_FT_ERROR }, 39 { ngx_string("error"), NGX_HTTP_PROXY_FT_ERROR },
35 { ngx_string("timeout"), NGX_HTTP_PROXY_FT_TIMEOUT }, 40 { ngx_string("timeout"), NGX_HTTP_PROXY_FT_TIMEOUT },
76 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 81 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
77 ngx_conf_set_msec_slot, 82 ngx_conf_set_msec_slot,
78 NGX_HTTP_LOC_CONF_OFFSET, 83 NGX_HTTP_LOC_CONF_OFFSET,
79 offsetof(ngx_http_proxy_loc_conf_t, send_timeout), 84 offsetof(ngx_http_proxy_loc_conf_t, send_timeout),
80 NULL }, 85 NULL },
86
87 { ngx_string("proxy_send_lowat"),
88 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
89 ngx_conf_set_size_slot,
90 NGX_HTTP_LOC_CONF_OFFSET,
91 offsetof(ngx_http_proxy_loc_conf_t, send_lowat),
92 &ngx_http_proxy_lowat_post },
81 93
82 { ngx_string("proxy_preserve_host"), 94 { ngx_string("proxy_preserve_host"),
83 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, 95 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
84 ngx_conf_set_flag_slot, 96 ngx_conf_set_flag_slot,
85 NGX_HTTP_LOC_CONF_OFFSET, 97 NGX_HTTP_LOC_CONF_OFFSET,
875 887
876 */ 888 */
877 889
878 conf->connect_timeout = NGX_CONF_UNSET_MSEC; 890 conf->connect_timeout = NGX_CONF_UNSET_MSEC;
879 conf->send_timeout = NGX_CONF_UNSET_MSEC; 891 conf->send_timeout = NGX_CONF_UNSET_MSEC;
892 conf->send_lowat = NGX_CONF_UNSET_SIZE;
880 893
881 conf->preserve_host = NGX_CONF_UNSET; 894 conf->preserve_host = NGX_CONF_UNSET;
882 conf->set_x_real_ip = NGX_CONF_UNSET; 895 conf->set_x_real_ip = NGX_CONF_UNSET;
883 conf->add_x_forwarded_for = NGX_CONF_UNSET; 896 conf->add_x_forwarded_for = NGX_CONF_UNSET;
884 897
918 size_t size; 931 size_t size;
919 932
920 ngx_conf_merge_msec_value(conf->connect_timeout, 933 ngx_conf_merge_msec_value(conf->connect_timeout,
921 prev->connect_timeout, 60000); 934 prev->connect_timeout, 60000);
922 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000); 935 ngx_conf_merge_msec_value(conf->send_timeout, prev->send_timeout, 60000);
936 ngx_conf_merge_size_value(conf->send_lowat, prev->send_lowat, 0);
923 937
924 ngx_conf_merge_value(conf->preserve_host, prev->preserve_host, 0); 938 ngx_conf_merge_value(conf->preserve_host, prev->preserve_host, 0);
925 ngx_conf_merge_value(conf->set_x_real_ip, prev->set_x_real_ip, 0); 939 ngx_conf_merge_value(conf->set_x_real_ip, prev->set_x_real_ip, 0);
926 ngx_conf_merge_value(conf->add_x_forwarded_for, 940 ngx_conf_merge_value(conf->add_x_forwarded_for,
927 prev->add_x_forwarded_for, 0); 941 prev->add_x_forwarded_for, 0);
1071 1085
1072 1086
1073 value = cf->args->elts; 1087 value = cf->args->elts;
1074 1088
1075 if (ngx_strncasecmp(value[1].data, "http://", 7) != 0) { 1089 if (ngx_strncasecmp(value[1].data, "http://", 7) != 0) {
1076 return "invalid URL prefix"; 1090 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid URL prefix");
1077 } 1091 return NGX_CONF_ERROR;
1078 1092 }
1079 ngx_test_null(lcf->upstream, 1093
1080 ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_upstream_conf_t)), 1094 lcf->upstream = ngx_pcalloc(cf->pool,
1081 NGX_CONF_ERROR); 1095 sizeof(ngx_http_proxy_upstream_conf_t));
1096 if (lcf->upstream == NULL) {
1097 return NGX_CONF_ERROR;
1098 }
1082 1099
1083 lcf->upstream->url.len = value[1].len; 1100 lcf->upstream->url.len = value[1].len;
1084 if (!(lcf->upstream->url.data = ngx_palloc(cf->pool, value[1].len + 1))) { 1101 if (!(lcf->upstream->url.data = ngx_palloc(cf->pool, value[1].len + 1))) {
1085 return NGX_CONF_ERROR; 1102 return NGX_CONF_ERROR;
1086 } 1103 }
1104
1087 ngx_cpystrn(lcf->upstream->url.data, value[1].data, value[1].len + 1); 1105 ngx_cpystrn(lcf->upstream->url.data, value[1].data, value[1].len + 1);
1088 1106
1089 value[1].data += 7; 1107 value[1].data += 7;
1090 value[1].len -= 7; 1108 value[1].len -= 7;
1091 1109
1092 err = ngx_http_proxy_parse_upstream(&value[1], lcf->upstream); 1110 err = ngx_http_proxy_parse_upstream(&value[1], lcf->upstream);
1093 1111
1094 if (err) { 1112 if (err) {
1095 return err; 1113 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, err);
1096 } 1114 return NGX_CONF_ERROR;
1097 1115 }
1098 ngx_test_null(host, ngx_palloc(cf->pool, lcf->upstream->host.len + 1), 1116
1099 NGX_CONF_ERROR); 1117 if (!(host = ngx_palloc(cf->pool, lcf->upstream->host.len + 1))) {
1118 return NGX_CONF_ERROR;
1119 }
1120
1100 ngx_cpystrn(host, lcf->upstream->host.data, lcf->upstream->host.len + 1); 1121 ngx_cpystrn(host, lcf->upstream->host.data, lcf->upstream->host.len + 1);
1101 1122
1102 /* AF_INET only */ 1123 /* AF_INET only */
1103 1124
1104 addr = inet_addr((char *) host); 1125 addr = inet_addr((char *) host);
1113 1134
1114 for (i = 0; h->h_addr_list[i] != NULL; i++) { /* void */ } 1135 for (i = 0; h->h_addr_list[i] != NULL; i++) { /* void */ }
1115 1136
1116 /* MP: ngx_shared_palloc() */ 1137 /* MP: ngx_shared_palloc() */
1117 1138
1118 ngx_test_null(lcf->peers, 1139 lcf->peers = ngx_pcalloc(cf->pool,
1119 ngx_pcalloc(cf->pool, 1140 sizeof(ngx_peers_t) + sizeof(ngx_peer_t) * (i - 1));
1120 sizeof(ngx_peers_t) 1141
1121 + sizeof(ngx_peer_t) * (i - 1)), 1142 if (lcf->peers == NULL) {
1122 NGX_CONF_ERROR); 1143 return NGX_CONF_ERROR;
1144 }
1123 1145
1124 lcf->peers->number = i; 1146 lcf->peers->number = i;
1125 1147
1126 for (i = 0; h->h_addr_list[i] != NULL; i++) { 1148 for (i = 0; h->h_addr_list[i] != NULL; i++) {
1127 lcf->peers->peers[i].host.data = host; 1149 lcf->peers->peers[i].host.data = host;
1128 lcf->peers->peers[i].host.len = lcf->upstream->host.len; 1150 lcf->peers->peers[i].host.len = lcf->upstream->host.len;
1129 lcf->peers->peers[i].addr = *(in_addr_t *)(h->h_addr_list[i]); 1151 lcf->peers->peers[i].addr = *(in_addr_t *)(h->h_addr_list[i]);
1130 lcf->peers->peers[i].port = lcf->upstream->port; 1152 lcf->peers->peers[i].port = lcf->upstream->port;
1131 1153
1132 len = INET_ADDRSTRLEN + lcf->upstream->port_text.len + 1; 1154 len = INET_ADDRSTRLEN + lcf->upstream->port_text.len + 1;
1133 ngx_test_null(lcf->peers->peers[i].addr_port_text.data, 1155
1134 ngx_palloc(cf->pool, len), 1156 lcf->peers->peers[i].addr_port_text.data =
1135 NGX_CONF_ERROR); 1157 ngx_palloc(cf->pool, len);
1158 if (lcf->peers->peers[i].addr_port_text.data == NULL) {
1159 return NGX_CONF_ERROR;
1160 }
1136 1161
1137 len = ngx_inet_ntop(AF_INET, 1162 len = ngx_inet_ntop(AF_INET,
1138 &lcf->peers->peers[i].addr, 1163 &lcf->peers->peers[i].addr,
1139 lcf->peers->peers[i].addr_port_text.data, 1164 lcf->peers->peers[i].addr_port_text.data,
1140 len); 1165 len);
1151 1176
1152 } else { 1177 } else {
1153 1178
1154 /* MP: ngx_shared_palloc() */ 1179 /* MP: ngx_shared_palloc() */
1155 1180
1156 ngx_test_null(lcf->peers, ngx_pcalloc(cf->pool, sizeof(ngx_peers_t)), 1181 if (!(lcf->peers = ngx_pcalloc(cf->pool, sizeof(ngx_peers_t)))) {
1157 NGX_CONF_ERROR); 1182 return NGX_CONF_ERROR;
1183 }
1158 1184
1159 lcf->peers->number = 1; 1185 lcf->peers->number = 1;
1160 1186
1161 lcf->peers->peers[0].host.data = host; 1187 lcf->peers->peers[0].host.data = host;
1162 lcf->peers->peers[0].host.len = lcf->upstream->host.len; 1188 lcf->peers->peers[0].host.len = lcf->upstream->host.len;
1163 lcf->peers->peers[0].addr = addr; 1189 lcf->peers->peers[0].addr = addr;
1164 lcf->peers->peers[0].port = lcf->upstream->port; 1190 lcf->peers->peers[0].port = lcf->upstream->port;
1165 1191
1166 len = lcf->upstream->host.len + lcf->upstream->port_text.len + 1; 1192 len = lcf->upstream->host.len + lcf->upstream->port_text.len + 1;
1167 1193
1168 ngx_test_null(lcf->peers->peers[0].addr_port_text.data, 1194 lcf->peers->peers[0].addr_port_text.data =
1169 ngx_palloc(cf->pool, len + 1), 1195 ngx_palloc(cf->pool, len + 1);
1170 NGX_CONF_ERROR); 1196 if (lcf->peers->peers[0].addr_port_text.data == NULL) {
1197 return NGX_CONF_ERROR;
1198 }
1171 1199
1172 len = lcf->upstream->host.len; 1200 len = lcf->upstream->host.len;
1173 1201
1174 ngx_memcpy(lcf->peers->peers[0].addr_port_text.data, 1202 ngx_memcpy(lcf->peers->peers[0].addr_port_text.data,
1175 lcf->upstream->host.data, len); 1203 lcf->upstream->host.data, len);
1276 } 1304 }
1277 } 1305 }
1278 1306
1279 return "invalid port in upstream URL"; 1307 return "invalid port in upstream URL";
1280 } 1308 }
1309
1310
1311 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data)
1312 {
1313 #if __FreeBSD__
1314
1315 ssize_t *np = data;
1316
1317 if (*np >= ngx_freebsd_net_inet_tcp_sendspace) {
1318 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1319 "\"proxy_send_lowat\" must be less than %d "
1320 "(sysctl net.inet.tcp.sendspace)",
1321 ngx_freebsd_net_inet_tcp_sendspace);
1322
1323 return NGX_CONF_ERROR;
1324 }
1325
1326
1327 #else
1328
1329 #if 0
1330 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
1331 "\"proxy_send_lowat\" is not supported, ignored");
1332
1333 *np = 0;
1334 #endif
1335
1336 #endif
1337
1338 return NGX_CONF_OK;
1339 }