From b541b6745905ca70db2bddf9f7726978e6d62a8f Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Sun, 30 Dec 2018 14:51:58 -0500 Subject: [PATCH] [core] use con->server_name for dir redir use con->server_name for dir redir if con->server_name is not empty and Host header not provided in request. --- src/http-header-glue.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/http-header-glue.c b/src/http-header-glue.c index 72e5e611..a6e9adbe 100644 --- a/src/http-header-glue.c +++ b/src/http-header-glue.c @@ -41,11 +41,19 @@ int http_response_buffer_append_authority(server *srv, connection *con, buffer * return -1; } + if (our_addr.plain.sa_family == AF_INET + && our_addr.ipv4.sin_addr.s_addr == htonl(INADDR_LOOPBACK)) { + buffer_append_string_len(o, CONST_STR_LEN("localhost")); + } else if (!buffer_string_is_empty(con->server_name)) { + buffer_append_string_buffer(o, con->server_name); + } else /* Lookup name: secondly try to get hostname for bind address */ if (0 != sock_addr_nameinfo_append_buffer(srv, o, &our_addr)) { con->http_status = 500; return -1; - } else { + } + + { unsigned short listen_port = sock_addr_get_port(&our_addr); unsigned short default_port = 80; if (buffer_is_equal_caseless_string(con->uri.scheme, CONST_STR_LEN("https"))) {