changeset 70:8ad297c88dcb NGINX_0_1_35

nginx 0.1.35 *) Feature: the "working_directory" directive. *) Feature: the "port_in_redirect" directive. *) Bugfix: the segmentation fault was occurred if the backend response header was in several packets; bug appeared in 0.1.29. *) Bugfix: if more than 10 servers were configured or some server did not use the "listen" directive, then the segmentation fault was occurred on the start. *) Bugfix: the segmentation fault might occur if the response was bigger than the temporary file. *) Bugfix: nginx returned the 400 response on requests like "GET http://www.domain.com/uri HTTP/1.0"; bug appeared in 0.1.28.
author Igor Sysoev <http://sysoev.ru>
date Tue, 07 Jun 2005 00:00:00 +0400
parents cce7ea52608c
children 66f1f40f29d6
files CHANGES CHANGES.ru auto/cc/gcc auto/cc/icc auto/modules auto/sources src/core/nginx.c src/core/nginx.h src/core/ngx_connection.c src/core/ngx_connection.h src/core/ngx_cycle.h src/core/ngx_string.c src/core/ngx_string.h src/event/ngx_event_pipe.c src/http/modules/ngx_http_proxy_module.c src/http/ngx_http.c src/http/ngx_http_config.h src/http/ngx_http_core_module.c src/http/ngx_http_core_module.h src/http/ngx_http_header_filter_module.c src/http/ngx_http_parse.c src/http/ngx_http_request.c src/os/unix/ngx_process_cycle.c
diffstat 23 files changed, 208 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,23 @@
+
+Changes with nginx 0.1.35                                        07 Jun 2005
+
+    *) Feature: the "working_directory" directive.
+
+    *) Feature: the "port_in_redirect" directive.
+
+    *) Bugfix: the segmentation fault was occurred if the backend response 
+       header was in several packets; bug appeared in 0.1.29.
+
+    *) Bugfix: if more than 10 servers were configured or some server did 
+       not use the "listen" directive, then the segmentation fault was 
+       occurred on the start.
+
+    *) Bugfix: the segmentation fault might occur if the response was 
+       bigger than the temporary file.
+
+    *) Bugfix: nginx returned the 400 response on requests like 
+       "GET http://www.domain.com/uri HTTP/1.0"; bug appeared in 0.1.28.
+
 
 Changes with nginx 0.1.34                                        26 May 2005
 
--- a/CHANGES.ru
+++ b/CHANGES.ru
@@ -1,3 +1,23 @@
+
+Изменения в nginx 0.1.35                                          07.06.2005
+
+    *) Добавление: директива working_directory.
+
+    *) Добавление: директива port_in_redirect.
+
+    *) Исправление: если заголовок ответа бэкенда не помещался в один 
+       пакет, то происходил segmentation fault; ошибка появилась в 0.1.29.
+
+    *) Исправление: если было сконфигурировано более 10 серверов или в 
+       сервере не описана директива "listen", то при запуске мог произойти 
+       segmentation fault.
+
+    *) Исправление: если ответ не помещался во временный файл, то мог 
+       произойти segmentation fault.
+
+    *) Исправление: nginx возвращал ошибку 400 на запросы вида 
+       "GET http://www.domain.com/uri HTTP/1.0"; ошибка появилась в 0.1.28.
+
 
 Изменения в nginx 0.1.34                                          26.05.2005
 
--- a/auto/cc/gcc
+++ b/auto/cc/gcc
@@ -4,7 +4,7 @@
 
 # gcc 2.7.2.3, 2.8.1, 2.95.4, egcs-1.1.2
 #     3.0.4, 3.1.1, 3.2.3, 3.3.2, 3.3.3, 3.3.4, 3.4.0, 3.4.2
-#     4.0.0
+#     4.0.0, 4.0.1, 4.1.0
 
 
 NGX_GCC_VER=`$CC -v 2>&1 | grep 'gcc version' 2>&1 \
@@ -57,6 +57,11 @@ case $CPU in
         CPU_OPT="-march=pentium4"
     ;;
 
+    athlon)
+        # optimize for Athlon, gcc 3.x
+        CPU_OPT="-march=athlon"
+    ;;
+
     opteron)
         # optimize for Opteron, gcc 3.x
         CPU_OPT="-march=opteron"
--- a/auto/cc/icc
+++ b/auto/cc/icc
@@ -4,6 +4,12 @@
 
 # Intel C++ compiler 7.1, 8.0, 8.1
 
+NGX_ICC_VER=`$CC -V 2>&1 | grep 'Version' 2>&1 \
+                         | sed -e 's/^.* Version \(.*\)   Build.*$/\1/'`
+
+echo " + icc version: $NGX_ICC_VER"
+
+
 # optimizations
 
 CFLAGS="$CFLAGS -O"
@@ -72,8 +78,6 @@ CFLAGS="$CFLAGS -wd269"
 CFLAGS="$CFLAGS -wd810"
 # parameter was never referenced
 CFLAGS="$CFLAGS -wd869"
-# "cc" clobber ignored, warnings for Liunx's htons()
-CFLAGS="$CFLAGS -wd1469"
 
 # STUB
 # enumerated type mixed with another type
@@ -86,8 +90,20 @@ CFLAGS="$CFLAGS -wd981"
 CFLAGS="$CFLAGS -wd1418"
 # external declaration in primary source file
 CFLAGS="$CFLAGS -wd1419"
-# non-POD class type passed through ellipsis
-CFLAGS="$CFLAGS -wd1595"
+
+case "$NGX_ICC_VER" in
+    8.*)
+        # "cc" clobber ignored, warnings for Liunx's htons()
+        CFLAGS="$CFLAGS -wd1469"
+
+        # STUB
+        # non-POD class type passed through ellipsis
+        CFLAGS="$CFLAGS -wd1595"
+    ;;
+
+    *)
+    ;;
+esac
 
 # stop on warning
 CFLAGS="$CFLAGS -Werror"
--- a/auto/modules
+++ b/auto/modules
@@ -51,6 +51,12 @@ if [ $NGX_TEST_BUILD_SOLARIS_SENDFILEV =
 fi
 
 
+if [ $HTTP != YES ]; then
+    have=NGX_CRYPT . auto/nohave
+    CRYPT_LIB=
+fi
+
+
 if [ $HTTP_SSI = YES ]; then
     HTTP_POSTPONE=YES
 fi
@@ -219,10 +225,14 @@ if [ $HTTP = YES ]; then
 fi
 
 
-IMAP_MODULES=$IMAP_MODULE
-
 if [ $IMAP = YES ]; then
     modules="$modules $IMAP_MODULES"
+
+    modules="$modules $IMAP_AUTH_HTTP_MODULE"
+    IMAP_SRCS="$IMAP_SRCS $IMAP_AUTH_HTTP_SRCS"
+
+    modules="$modules $IMAP_PROXY_MODULE"
+    IMAP_SRCS="$IMAP_SRCS $IMAP_PROXY_SRCS"
 fi
 
 
--- a/auto/sources
+++ b/auto/sources
@@ -339,8 +339,15 @@ IMAP_INCS="src/imap"
 
 IMAP_DEPS="src/imap/ngx_imap.h"
 
-IMAP_MODULE=ngx_imap_module
+IMAP_MODULES="ngx_imap_module ngx_imap_core_module"
+
 IMAP_SRCS="src/imap/ngx_imap.c \
+           src/imap/ngx_imap_core_module.c \
            src/imap/ngx_imap_handler.c \
-           src/imap/ngx_imap_parse.c \
-           src/imap/ngx_imap_proxy.c"
+           src/imap/ngx_imap_parse.c"
+
+IMAP_AUTH_HTTP_MODULE="ngx_imap_auth_http_module"
+IMAP_AUTH_HTTP_SRCS="src/imap/ngx_imap_auth_http_module.c"
+
+IMAP_PROXY_MODULE="ngx_imap_proxy_module"
+IMAP_PROXY_SRCS="src/imap/ngx_imap_proxy_module.c"
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -95,6 +95,13 @@ static ngx_command_t  ngx_core_commands[
       offsetof(ngx_core_conf_t, pid),
       NULL },
 
+    { ngx_string("working_directory"),
+      NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
+      ngx_conf_set_str_slot,
+      0,
+      offsetof(ngx_core_conf_t, working_directory),
+      NULL },
+
       ngx_null_command
 };
 
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -8,7 +8,7 @@
 #define _NGINX_H_INCLUDED_
 
 
-#define NGINX_VER          "nginx/0.1.34"
+#define NGINX_VER          "nginx/0.1.35"
 
 #define NGINX_VAR          "NGINX"
 #define NGX_NEWPID_EXT     ".newbin"
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -12,9 +12,8 @@
 ngx_os_io_t  ngx_io;
 
 
-ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf,
-                                                  in_addr_t addr,
-                                                  in_port_t port)
+ngx_listening_t *
+ngx_listening_inet_stream_socket(ngx_conf_t *cf, in_addr_t addr, in_port_t port)
 {
     size_t               len;
     ngx_listening_t     *ls;
@@ -60,7 +59,8 @@ ngx_listening_t *ngx_listening_inet_stre
 }
 
 
-ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle)
+ngx_int_t
+ngx_set_inherited_sockets(ngx_cycle_t *cycle)
 {
     size_t               len;
     ngx_uint_t           i;
@@ -121,7 +121,8 @@ ngx_int_t ngx_set_inherited_sockets(ngx_
 }
 
 
-ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle)
+ngx_int_t
+ngx_open_listening_sockets(ngx_cycle_t *cycle)
 {
     ngx_uint_t        tries, failed, reuseaddr, i;
     ngx_err_t         err;
@@ -261,7 +262,8 @@ ngx_int_t ngx_open_listening_sockets(ngx
 }
 
 
-void ngx_close_listening_sockets(ngx_cycle_t *cycle)
+void
+ngx_close_listening_sockets(ngx_cycle_t *cycle)
 {
     ngx_uint_t        i;
     ngx_socket_t      fd;
@@ -309,7 +311,8 @@ void ngx_close_listening_sockets(ngx_cyc
 }
 
 
-void ngx_close_connection(ngx_connection_t *c)
+void
+ngx_close_connection(ngx_connection_t *c)
 {
     ngx_socket_t  fd;
 
@@ -398,7 +401,8 @@ void ngx_close_connection(ngx_connection
 }
 
 
-ngx_int_t ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text)
+ngx_int_t
+ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text)
 {
     ngx_uint_t  level;
 
--- a/src/core/ngx_connection.h
+++ b/src/core/ngx_connection.h
@@ -144,8 +144,7 @@ struct ngx_connection_s {
 
 
 ngx_listening_t *ngx_listening_inet_stream_socket(ngx_conf_t *cf,
-                                                 in_addr_t addr,
-                                                 in_port_t port);
+    in_addr_t addr, in_port_t port);
 ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle);
 ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle);
 void ngx_close_listening_sockets(ngx_cycle_t *cycle);
--- a/src/core/ngx_cycle.h
+++ b/src/core/ngx_cycle.h
@@ -57,6 +57,8 @@ typedef struct {
      ngx_uid_t                user;
      ngx_gid_t                group;
 
+     ngx_str_t                working_directory;
+
      ngx_str_t                pid;
      ngx_str_t                newpid;
 
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -792,8 +792,30 @@ ngx_escape_uri(u_char *dst, u_char *src,
           0xffffffff, /* 1111 1111 1111 1111  1111 1111 1111 1111 */
           0xffffffff  /* 1111 1111 1111 1111  1111 1111 1111 1111 */ };
 
+                      /* " ", """, "%", "'", %00-%1F, %7F-%FF */
+
+    static uint32_t   utf[] =
+        { 0xffffffff, /* 1111 1111 1111 1111  1111 1111 1111 1111 */
+
+                      /* ?>=< ;:98 7654 3210  /.-, +*)( '&%$ #"!  */
+          0x800000ad, /* 0000 0000 0000 0000  0000 0000 1010 1101 */
+
+                      /* _^]\ [ZYX WVUT SRQP  ONML KJIH GFED CBA@ */
+          0x00000000, /* 0000 0000 0000 0000  0000 0000 0000 0000 */
+
+                      /*  ~}| {zyx wvut srqp  onml kjih gfed cba` */
+          0x80000000, /* 1000 0000 0000 0000  0000 0000 0000 0000 */
+
+          0x00000000, /* 0000 0000 0000 0000  0000 0000 0000 0000 */
+          0x00000000, /* 0000 0000 0000 0000  0000 0000 0000 0000 */
+          0x00000000, /* 0000 0000 0000 0000  0000 0000 0000 0000 */
+          0x00000000  /* 0000 0000 0000 0000  0000 0000 0000 0000 */ };
+
 
     switch (type) {
+    case NGX_ESCAPE_UTF:
+        escape = utf;
+        break;
     case NGX_ESCAPE_HTML:
         escape = html;
         break;
--- a/src/core/ngx_string.h
+++ b/src/core/ngx_string.h
@@ -100,6 +100,7 @@ ngx_int_t ngx_decode_base64(ngx_str_t *d
 #define NGX_ESCAPE_URI   0
 #define NGX_ESCAPE_ARGS  1
 #define NGX_ESCAPE_HTML  2
+#define NGX_ESCAPE_UTF   3
 
 uintptr_t ngx_escape_uri(u_char *dst, u_char *src, size_t size,
     ngx_uint_t type);
--- a/src/event/ngx_event_pipe.c
+++ b/src/event/ngx_event_pipe.c
@@ -210,6 +210,10 @@ static ngx_int_t ngx_event_pipe_read_ups
                 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
                                "pipe temp offset: %O", p->temp_file->offset);
 
+                if (rc == NGX_BUSY) {
+                    break;
+                }
+
                 if (rc == NGX_AGAIN) {
                     if (ngx_event_flags & NGX_USE_LEVEL_EVENT
                         && p->upstream->read->active
@@ -617,6 +621,10 @@ static ngx_int_t ngx_event_pipe_write_ch
 
         ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "size: %z", size);
 
+        if (ll == NULL) {
+            return NGX_BUSY;
+        }
+
         if (cl) {
            p->in = cl;
            *ll = NULL;
--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -1013,6 +1013,10 @@ ngx_http_proxy_process_header(ngx_http_r
             return NGX_OK;
         }
 
+        if (rc == NGX_AGAIN) {
+            return NGX_AGAIN;
+        }
+
         /* there was error while a header line parsing */
 
         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -360,7 +360,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_comma
      * to quickly find the server core module configuration at run-time
      */
 
-    if (ngx_array_init(&in_ports, cf->pool, 10, sizeof(ngx_http_in_port_t))
+    if (ngx_array_init(&in_ports, cf->pool, 2, sizeof(ngx_http_in_port_t))
         != NGX_OK)
     {
         return NGX_CONF_ERROR;
@@ -434,6 +434,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_comma
                             if (inaddr == NULL) {
                                 return NGX_CONF_ERROR;
                             }
+                            in_addr = in_port[p].addrs.elts;
 
                             /*
                              * the INADDR_ANY must be the last resort
@@ -578,7 +579,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_comma
                 }
 
                 for (n = 0; n < cmcf->server_names_hash; n++) {
-                    if (ngx_array_init(&in_addr[a].hash[n], cf->pool, 5,
+                    if (ngx_array_init(&in_addr[a].hash[n], cf->pool, 4,
                                      sizeof(ngx_http_server_name_t)) != NGX_OK)
                     {
                         return NGX_CONF_ERROR;
@@ -595,6 +596,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_comma
                     if (s_name == NULL) {
                         return NGX_CONF_ERROR;
                     }
+                    name = in_addr[a].names.elts;
 
                     *s_name = name[s];
                 }
@@ -748,7 +750,7 @@ ngx_http_add_address(ngx_conf_t *cf, ngx
     ngx_http_in_addr_t  *in_addr;
 
     if (in_port->addrs.elts == NULL) {
-        if (ngx_array_init(&in_port->addrs, cf->pool, 10,
+        if (ngx_array_init(&in_port->addrs, cf->pool, 4,
                            sizeof(ngx_http_in_addr_t)) != NGX_OK)
         {
             return NGX_ERROR;
@@ -794,7 +796,7 @@ ngx_http_add_names(ngx_conf_t *cf, ngx_h
     ngx_http_server_name_t  *server_names, *name;
 
     if (in_addr->names.elts == NULL) {
-        if (ngx_array_init(&in_addr->names, cf->pool, 10,
+        if (ngx_array_init(&in_addr->names, cf->pool, 4,
                            sizeof(ngx_http_server_name_t)) != NGX_OK)
         {
             return NGX_ERROR;
@@ -802,7 +804,7 @@ ngx_http_add_names(ngx_conf_t *cf, ngx_h
     }
 
     if (in_addr->wildcards.elts == NULL) {
-        if (ngx_array_init(&in_addr->wildcards, cf->pool, 10,
+        if (ngx_array_init(&in_addr->wildcards, cf->pool, 1,
                            sizeof(ngx_http_server_name_t)) != NGX_OK)
         {
             return NGX_ERROR;
@@ -834,6 +836,7 @@ ngx_http_add_names(ngx_conf_t *cf, ngx_h
         if (name == NULL) {
             return NGX_ERROR;
         }
+        server_names = cscf->server_names.elts;
 
         *name = server_names[i];
     }
--- a/src/http/ngx_http_config.h
+++ b/src/http/ngx_http_config.h
@@ -8,7 +8,8 @@
 #define _NGX_HTTP_CONFIG_H_INCLUDED_
 
 
-#include <ngx_alloc.h>
+#include <ngx_config.h>
+#include <ngx_core.h>
 #include <ngx_http.h>
 
 
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -319,6 +319,13 @@ static ngx_command_t  ngx_http_core_comm
       offsetof(ngx_http_core_loc_conf_t, reset_timedout_connection),
       NULL },
 
+    { ngx_string("port_in_redirect"),
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
+      ngx_conf_set_flag_slot,
+      NGX_HTTP_LOC_CONF_OFFSET,
+      offsetof(ngx_http_core_loc_conf_t, port_in_redirect),
+      NULL },
+
     { ngx_string("msie_padding"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
       ngx_conf_set_flag_slot,
@@ -1113,10 +1120,10 @@ ngx_http_delay_handler(ngx_http_request_
 static char *
 ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
 {
-    int                         m;
     char                       *rv;
     void                       *mconf;
-    ngx_conf_t                  save;
+    ngx_uint_t                  m;
+    ngx_conf_t                  pcf;
     ngx_http_module_t          *module;
     ngx_http_conf_ctx_t        *ctx, *http_ctx;
     ngx_http_core_srv_conf_t   *cscf, **cscfp;
@@ -1189,13 +1196,13 @@ ngx_http_core_server(ngx_conf_t *cf, ngx
 
     /* parse inside server{} */
 
-    save = *cf;
+    pcf = *cf;
     cf->ctx = ctx;
     cf->cmd_type = NGX_HTTP_SRV_CONF;
 
     rv = ngx_conf_parse(cf, NULL);
 
-    *cf = save;
+    *cf = pcf;
 
     if (rv != NGX_CONF_OK) {
         return rv;
@@ -1622,6 +1629,7 @@ ngx_http_core_merge_srv_conf(ngx_conf_t 
         ls->port = (getuid() == 0) ? 80 : 8000;
 #endif
         ls->family = AF_INET;
+        ls->default_server = 0;
     }
 
     if (conf->server_names.nelts == 0) {
@@ -1726,6 +1734,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t
     lcf->lingering_time = NGX_CONF_UNSET_MSEC;
     lcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
     lcf->reset_timedout_connection = NGX_CONF_UNSET;
+    lcf->port_in_redirect = NGX_CONF_UNSET;
     lcf->msie_padding = NGX_CONF_UNSET;
 
     return lcf;
@@ -1839,6 +1848,7 @@ ngx_http_core_merge_loc_conf(ngx_conf_t 
 
     ngx_conf_merge_value(conf->reset_timedout_connection,
                               prev->reset_timedout_connection, 0);
+    ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1);
     ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
 
     if (conf->open_files == NULL) {
@@ -1857,8 +1867,8 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx
     u_char             *addr;
     ngx_int_t           port;
     ngx_uint_t          p;
+    ngx_str_t          *args;
     struct hostent     *h;
-    ngx_str_t          *args;
     ngx_http_listen_t  *ls;
 
     /*
@@ -1874,9 +1884,9 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx
     /* AF_INET only */
 
     ls->family = AF_INET;
-    ls->default_server = 0;
     ls->file_name = cf->conf_file->file.name;
     ls->line = cf->conf_file->line;
+    ls->default_server = 0;
 
     args = cf->args->elts;
     addr = args[1].data;
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -20,7 +20,7 @@ typedef struct {
     ngx_str_t                  file_name;
     ngx_int_t                  line;
 
-    unsigned                   default_server:1;
+    ngx_uint_t                 default_server; /* unsigned  default_server:1; */
 } ngx_http_listen_t;
 
 
@@ -206,6 +206,7 @@ struct ngx_http_core_loc_conf_s {
     ngx_flag_t    tcp_nopush;              /* tcp_nopush */
     ngx_flag_t    tcp_nodelay;             /* tcp_nodelay */
     ngx_flag_t    reset_timedout_connection; /* reset_timedout_connection */
+    ngx_flag_t    port_in_redirect;        /* port_in_redirect */
     ngx_flag_t    msie_padding;            /* msie_padding */
 
     ngx_array_t  *error_pages;             /* error_page */
--- a/src/http/ngx_http_header_filter_module.c
+++ b/src/http/ngx_http_header_filter_module.c
@@ -258,6 +258,8 @@ ngx_http_header_filter(ngx_http_request_
         len += sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1;
     }
 
+    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
     if (r->headers_out.location
         && r->headers_out.location->value.len
         && r->headers_out.location->value.data[0] == '/')
@@ -270,7 +272,7 @@ ngx_http_header_filter(ngx_http_request_
                    + r->server_name.len
                    + r->headers_out.location->value.len + 2;
 
-            if (r->port != 443) {
+            if (clcf->port_in_redirect && r->port != 443) {
                 len += r->port_text->len;
             }
 
@@ -281,7 +283,7 @@ ngx_http_header_filter(ngx_http_request_
                    + r->server_name.len
                    + r->headers_out.location->value.len + 2;
 
-            if (r->port != 80) {
+            if (clcf->port_in_redirect && r->port != 80) {
                 len += r->port_text->len;
             }
         }
@@ -291,8 +293,6 @@ ngx_http_header_filter(ngx_http_request_
         len += sizeof("Transfer-Encoding: chunked" CRLF) - 1;
     }
 
-    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
     if (r->keepalive) {
         len += sizeof("Connection: keep-alive" CRLF) - 1;
 
@@ -425,18 +425,20 @@ ngx_http_header_filter(ngx_http_request_
         b->last = ngx_cpymem(b->last, r->server_name.data,
                              r->server_name.len);
 
+        if (clcf->port_in_redirect) {
 #if (NGX_HTTP_SSL)
-        if (r->connection->ssl) {
-            if (r->port != 443) {
-                b->last = ngx_cpymem(b->last, r->port_text->data,
-                                     r->port_text->len);
-            }
-        } else
+            if (r->connection->ssl) {
+                if (r->port != 443) {
+                    b->last = ngx_cpymem(b->last, r->port_text->data,
+                                         r->port_text->len);
+                }
+            } else
 #endif
-        {
-            if (r->port != 80) {
-                b->last = ngx_cpymem(b->last, r->port_text->data,
-                                     r->port_text->len);
+            {
+                if (r->port != 80) {
+                    b->last = ngx_cpymem(b->last, r->port_text->data,
+                                         r->port_text->len);
+                }
             }
         }
 
--- a/src/http/ngx_http_parse.c
+++ b/src/http/ngx_http_parse.c
@@ -112,7 +112,7 @@ ngx_http_parse_request_line(ngx_http_req
         case sw_spaces_before_uri:
 
             c = (u_char) (ch | 0x20);
-            if (c >= 'a' && c <= 'f') {
+            if (c >= 'a' && c <= 'z') {
                 r->schema_start = p;
                 state = sw_schema;
                 break;
@@ -133,7 +133,7 @@ ngx_http_parse_request_line(ngx_http_req
         case sw_schema:
 
             c = (u_char) (ch | 0x20);
-            if (c >= 'a' && c <= 'f') {
+            if (c >= 'a' && c <= 'z') {
                 break;
             }
 
@@ -171,7 +171,7 @@ ngx_http_parse_request_line(ngx_http_req
         case sw_host:
 
             c = (u_char) (ch | 0x20);
-            if (c >= 'a' && c <= 'f') {
+            if (c >= 'a' && c <= 'z') {
                 break;
             }
 
@@ -215,7 +215,7 @@ ngx_http_parse_request_line(ngx_http_req
         case sw_after_slash_in_uri:
 
             c = (u_char) (ch | 0x20);
-            if (c >= 'a' && c <= 'f') {
+            if (c >= 'a' && c <= 'z') {
                 state = sw_check_uri;
                 break;
             }
@@ -277,7 +277,7 @@ ngx_http_parse_request_line(ngx_http_req
         case sw_check_uri:
 
             c = (u_char) (ch | 0x20);
-            if (c >= 'a' && c <= 'f') {
+            if (c >= 'a' && c <= 'z') {
                 break;
             }
 
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -1722,6 +1722,10 @@ ngx_http_discard_body(ngx_http_request_t
     ssize_t       size;
     ngx_event_t  *rev;
 
+    if (r->main) {
+        return NGX_OK;
+    }
+
     rev = r->connection->read;
 
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http set discard body");
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -838,6 +838,15 @@ ngx_worker_process_init(ngx_cycle_t *cyc
 
 #endif
 
+    if (ccf->working_directory.len) {
+        if (chdir(ccf->working_directory.data) == -1) {
+            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                          "chdir(\"%s\") failed", ccf->working_directory.data);
+            /* fatal */
+            exit(2);
+        }
+    }
+
     sigemptyset(&set);
 
     if (sigprocmask(SIG_SETMASK, &set, NULL) == -1) {