diff --git a/src/buffer.c b/src/buffer.c index 776c7c75..8d3d5165 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -264,6 +264,16 @@ buffer_copy_path_len2 (buffer * const restrict b, const char * const restrict s1 buffer_append_path_len(b, s2, len2);/*(choice: not inlined, special-cased)*/ } +void +buffer_copy_string_len_lc (buffer * const restrict b, const char * const restrict s, const size_t len) +{ + char * const restrict d = buffer_string_prepare_copy(b, len); + b->used = len+1; + d[len] = '\0'; + for (size_t i = 0; i < len; ++i) + d[i] = (!light_isupper(s[i])) ? s[i] : s[i] | 0x20; +} + void buffer_append_uint_hex_lc(buffer *b, uintmax_t value) { char *buf; unsigned int shift = 0; diff --git a/src/buffer.h b/src/buffer.h index cf828a0f..1ebee556 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -107,6 +107,7 @@ void buffer_free_ptr(buffer *b); void buffer_copy_string(buffer * restrict b, const char * restrict s); void buffer_copy_string_len(buffer * restrict b, const char * restrict s, size_t len); +void buffer_copy_string_len_lc(buffer * restrict b, const char * restrict s, size_t len); void buffer_append_string(buffer * restrict b, const char * restrict s); void buffer_append_string_len(buffer * restrict b, const char * restrict s, size_t len); diff --git a/src/configfile.c b/src/configfile.c index 8c6f6397..a673ad99 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -2553,9 +2553,7 @@ int config_set_defaults(server *srv) { s->force_lowercase_filenames = 0; /* default to 0 */ buffer * const tb = srv->tmp_buf; - buffer_copy_buffer(tb, s->document_root); - - buffer_to_lower(tb); + buffer_copy_string_len_lc(tb, BUF_PTR_LEN(s->document_root)); if (0 == stat(tb->ptr, &st1)) { int is_lower = 0; diff --git a/src/mod_extforward.c b/src/mod_extforward.c index 74612f5a..7544d42b 100644 --- a/src/mod_extforward.c +++ b/src/mod_extforward.c @@ -949,16 +949,15 @@ static handler_t mod_extforward_Forwarded (request_st * const r, plugin_data * c while (vlen > v && (s[vlen-1] == ' ' || s[vlen-1] == '\t')) --vlen; if (vlen > v+1 && s[v] == '"' && s[vlen-1] == '"') { ++v; --vlen; - buffer_copy_string_len(r->http_host, s+v, vlen-v); + buffer_copy_string_len_lc(r->http_host, s+v, vlen-v); if (!buffer_backslash_unescape(r->http_host)) { return mod_extforward_bad_request(r, __LINE__, "invalid host= value in Forwarded header"); } } else { - buffer_copy_string_len(r->http_host, s+v, vlen-v); + buffer_copy_string_len_lc(r->http_host, s+v, vlen-v); } - buffer_to_lower(r->http_host); if (0 != http_request_host_policy(r->http_host, r->conf.http_parseopts, diff --git a/src/mod_gnutls.c b/src/mod_gnutls.c index 3ba60e0d..e9a892a2 100644 --- a/src/mod_gnutls.c +++ b/src/mod_gnutls.c @@ -1443,8 +1443,7 @@ mod_gnutls_SNI(handler_ctx * const hctx, } /* use SNI to patch mod_gnutls config and then reset COMP_HTTP_HOST */ - buffer_copy_string_len(&r->uri.authority, (const char *)servername, len); - buffer_to_lower(&r->uri.authority); + buffer_copy_string_len_lc(&r->uri.authority, (const char *)servername, len); #if 0 /*(r->uri.authority used below for configuration before request read; * revisit for h2)*/ diff --git a/src/mod_mbedtls.c b/src/mod_mbedtls.c index 7068c9fb..8c258706 100644 --- a/src/mod_mbedtls.c +++ b/src/mod_mbedtls.c @@ -711,8 +711,7 @@ mod_mbedtls_SNI (void *arg, mbedtls_ssl_context *ssl, const unsigned char *serve } /* use SNI to patch mod_mbedtls config and then reset COMP_HTTP_HOST */ - buffer_copy_string_len(&r->uri.authority, (const char *)servername, len); - buffer_to_lower(&r->uri.authority); + buffer_copy_string_len_lc(&r->uri.authority, (const char *)servername, len); #if 0 /*(r->uri.authority used below for configuration before request read; * revisit for h2)*/ diff --git a/src/mod_nss.c b/src/mod_nss.c index db5e63ad..db2b42ee 100644 --- a/src/mod_nss.c +++ b/src/mod_nss.c @@ -1393,8 +1393,7 @@ mod_nss_SNI (PRFileDesc *ssl, const SECItem *srvNameArr, PRUint32 srvNameArrSize } /* use SNI to patch mod_nss config and then reset COMP_HTTP_HOST */ - buffer_copy_string_len(&r->uri.authority, (const char *)sn->data, sn->len); - buffer_to_lower(&r->uri.authority); + buffer_copy_string_len_lc(&r->uri.authority,(const char *)sn->data,sn->len); #if 0 /*(r->uri.authority used below for configuration before request read; * revisit for h2)*/ diff --git a/src/mod_openssl.c b/src/mod_openssl.c index 6f4539dd..dd34d4cf 100644 --- a/src/mod_openssl.c +++ b/src/mod_openssl.c @@ -1190,8 +1190,7 @@ mod_openssl_SNI (handler_ctx *hctx, const char *servername, size_t len) } /* use SNI to patch mod_openssl config and then reset COMP_HTTP_HOST */ - buffer_copy_string_len(&r->uri.authority, servername, len); - buffer_to_lower(&r->uri.authority); + buffer_copy_string_len_lc(&r->uri.authority, servername, len); #if 0 /*(r->uri.authority used below for configuration before request read; * revisit for h2)*/ diff --git a/src/mod_wolfssl.c b/src/mod_wolfssl.c index 905f0ecb..96d5b150 100644 --- a/src/mod_wolfssl.c +++ b/src/mod_wolfssl.c @@ -1268,8 +1268,7 @@ mod_openssl_SNI (handler_ctx *hctx, const char *servername, size_t len) } /* use SNI to patch mod_openssl config and then reset COMP_HTTP_HOST */ - buffer_copy_string_len(&r->uri.authority, servername, len); - buffer_to_lower(&r->uri.authority); + buffer_copy_string_len_lc(&r->uri.authority, servername, len); #if 0 /*(r->uri.authority used below for configuration before request read; * revisit for h2)*/ diff --git a/src/request.c b/src/request.c index 523a7f89..d10774f6 100644 --- a/src/request.c +++ b/src/request.c @@ -270,8 +270,7 @@ static void http_request_header_set_Host(request_st * const restrict r, const ch { r->http_host = http_header_request_set_ptr(r, HTTP_HEADER_HOST, CONST_STR_LEN("Host")); - buffer_copy_string_len(r->http_host, h, hlen); - buffer_to_lower(r->http_host); + buffer_copy_string_len_lc(r->http_host, h, hlen); } diff --git a/src/response.c b/src/response.c index c139e2db..6aca7b60 100644 --- a/src/response.c +++ b/src/response.c @@ -622,10 +622,8 @@ static handler_t http_response_comeback (request_st * const r) request_config_reset(r); - if (__builtin_expect( (r->http_host != NULL), 1)) { - buffer_copy_buffer(&r->uri.authority, r->http_host); - buffer_to_lower(&r->uri.authority); - } + if (__builtin_expect( (r->http_host != NULL), 1)) + buffer_copy_string_len_lc(&r->uri.authority, BUF_PTR_LEN(r->http_host)); else /*(buffer_blank(&r->uri.authority) w/o code inline)*/ buffer_copy_string_len(&r->uri.authority, CONST_STR_LEN(""));