comparison src/http/ngx_http_core_module.c @ 56:058f01f78761

nginx-0.0.1-2003-01-29-20:02:48 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 29 Jan 2003 17:02:48 +0000
parents cad6c2f43283
children e8cdc2989cee
comparison
equal deleted inserted replaced
55:cad6c2f43283 56:058f01f78761
115 } else { 115 } else {
116 116
117 /* AF_INET only */ 117 /* AF_INET only */
118 118
119 in_port = (ngx_http_in_port_t *) r->connection->servers; 119 in_port = (ngx_http_in_port_t *) r->connection->servers;
120 in_addr = (ngx_http_in_addr_t *) in_port->addr.elts;
120 121
121 a = 0; 122 a = 0;
122 123
123 if (in_port->addr.nelts > 1) { 124 if (in_port->addr.nelts > 1) {
124 /* find r->in_addr, getsockname() */ 125 /* find r->in_addr, getsockname() */
125 126
126 in_addr = (ngx_http_in_addr_t *) in_port->addr.elts;
127 for ( /* void */ ; a < in_port->addr.nelts; a++) { 127 for ( /* void */ ; a < in_port->addr.nelts; a++) {
128 128
129 if (in_addr[a].addr == INADDR_ANY) { 129 if (in_addr[a].addr == INADDR_ANY) {
130 break; 130 break;
131 } 131 }
201 } 201 }
202 202
203 203
204 int ngx_http_core_translate_handler(ngx_http_request_t *r) 204 int ngx_http_core_translate_handler(ngx_http_request_t *r)
205 { 205 {
206 int i, rc, len, f_offset, l_offset; 206 int i, rc, len, port_len, f_offset, l_offset;
207 char *buf, *location, *last; 207 char *buf, *location, *last;
208 ngx_err_t err; 208 ngx_err_t err;
209 ngx_table_elt_t *h; 209 ngx_table_elt_t *h;
210 ngx_http_server_name_t *s_name; 210 ngx_http_server_name_t *s_name;
211 ngx_http_core_srv_conf_t *scf; 211 ngx_http_core_srv_conf_t *scf;
243 243
244 ngx_log_debug(r->connection->log, "doc_root: %08x" _ &loc_conf->doc_root); 244 ngx_log_debug(r->connection->log, "doc_root: %08x" _ &loc_conf->doc_root);
245 245
246 s_name = (ngx_http_server_name_t *) scf->server_names.elts; 246 s_name = (ngx_http_server_name_t *) scf->server_names.elts;
247 247
248 if (r->port == 0) {
249 #if 0
250 struct sockaddr_in *addr_in;
251 addr_in = (struct sockaddr_in *) r->connection->sockaddr;
252 r->port = ntohs(addr_in->sin_port);
253 #else
254 ngx_http_in_port_t *in_port;
255 in_port = (ngx_http_in_port_t *) r->connection->servers;
256 r->port = in_port->port;
257 #endif
258 if (r->port != 80) {
259 ngx_test_null(r->port_name.data, ngx_palloc(r->pool, 7),
260 NGX_HTTP_INTERNAL_SERVER_ERROR);
261 r->port_name.len = ngx_snprintf(r->port_name.data, 7, ":%d",
262 r->port);
263 }
264 }
265
266 port_len = (r->port != 80) ? r->port_name.len : 0;
267
248 /* "+ 7" is "http://" */ 268 /* "+ 7" is "http://" */
249 if (loc_conf->doc_root.len > s_name[0].name.len + 7) { 269 if (loc_conf->doc_root.len > 7 + s_name[0].name.len + port_len) {
250 len = loc_conf->doc_root.len; 270 len = loc_conf->doc_root.len;
251 f_offset = 0; 271 f_offset = 0;
252 l_offset = len - (s_name[0].name.len + 7); 272 l_offset = len - (7 + s_name[0].name.len + port_len);
253 273
254 } else { 274 } else {
255 len = s_name[0].name.len + 7; 275 len = 7 + s_name[0].name.len + port_len;
256 f_offset = len - loc_conf->doc_root.len; 276 f_offset = len - loc_conf->doc_root.len;
257 l_offset = 0; 277 l_offset = 0;
258 } 278 }
259 279
260 /* "+ 2" is for trailing '/' in redirect and '\0' */ 280 /* "+ 2" is for trailing '/' in redirect and '\0' */
365 ngx_test_null(h, ngx_push_table(r->headers_out.headers), 385 ngx_test_null(h, ngx_push_table(r->headers_out.headers),
366 NGX_HTTP_INTERNAL_SERVER_ERROR); 386 NGX_HTTP_INTERNAL_SERVER_ERROR);
367 387
368 ngx_memcpy(location, "http://", 7); 388 ngx_memcpy(location, "http://", 7);
369 ngx_memcpy(location + 7, s_name[0].name.data, s_name[0].name.len); 389 ngx_memcpy(location + 7, s_name[0].name.data, s_name[0].name.len);
390 if (port_len) {
391 ngx_memcpy(location + 7 + s_name[0].name.len, r->port_name.data,
392 port_len);
393 }
370 394
371 *last++ = '/'; 395 *last++ = '/';
372 *last = '\0'; 396 *last = '\0';
373 h->key.len = 8; 397 h->key.len = 8;
374 h->key.data = "Location" ; 398 h->key.data = "Location" ;