Repository: nginx/nginx
File: src/http/v2/ngx_http_v2.c (C)

Code before:
        ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
        goto failed;
    }

    if (r->host_end) {

        host.len = r->host_end - r->host_start;
        host.data = r->host_start;

        if (r->headers_in.host) {
            if (r->headers_in.host->value.len != host.len
                || ngx_memcmp(r->headers_in.host->value.data, host.data,
                              host.len)
                   != 0)
            {
                ngx_log_error(NGX_LOG_INFO, fc->log, 0,
                              "client sent \":authority\" and \"Host\" headers "
                              "with different values");
                ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
                goto failed;
            }

        } else {
            /* compatibility for $http_host */

            if (ngx_http_v2_construct_host_header(r, &host) != NGX_OK) {
                goto failed;
            }
        }
    }

    if (r->headers_in.content_length) {
        r->headers_in.content_length_n =
                            ngx_atoof(r->headers_in.content_length->value.data,
                                      r->headers_in.content_length->value.len);

        if (r->headers_in.content_length_n == NGX_ERROR) {
            ngx_log_error(NGX_LOG_INFO, fc->log, 0,
                          "client sent invalid \"Content-Length\" header");
            goto failed;
        }

        if (r->headers_in.content_length_n > 0 && r->stream->in_closed) {
            ngx_log_error(NGX_LOG_INFO, fc->log, 0,
                          "client prematurely closed stream");

            r->stream->skip_data = 1;

            ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
            goto failed;
        }

Review comment (suggestion):
We don't need to pass `host` to this function, it's available in `r`. This will make `ngx_http_v2_construct_host_header()` even more similar to `ngx_http_v2_construct_cookie_header()`.

Code after:

    if (r->headers_in.server.len == 0) {
        ngx_log_error(NGX_LOG_INFO, fc->log, 0,
                      "client sent neither \":authority\" nor \"Host\" header");
        ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
        goto failed;
    }

    if (r->host_end) {

        host.len = r->host_end - r->host_start;
        host.data = r->host_start;

        if (r->headers_in.host) {
            if (r->headers_in.host->value.len != host.len
                || ngx_memcmp(r->headers_in.host->value.data, host.data,
                              host.len)
                   != 0)
            {
                ngx_log_error(NGX_LOG_INFO, fc->log, 0,
                              "client sent \":authority\" and \"Host\" headers "
                              "with different values");
                ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
                goto failed;
            }

        } else {
            /* compatibility for $http_host */

            if (ngx_http_v2_construct_host_header(r) != NGX_OK) {
                goto failed;
            }
        }
    }

    if (r->headers_in.content_length) {
        r->headers_in.content_length_n =
                            ngx_atoof(r->headers_in.content_length->value.data,
                                      r->headers_in.content_length->value.len);

        if (r->headers_in.content_length_n == NGX_ERROR) {
            ngx_log_error(NGX_LOG_INFO, fc->log, 0,
                          "client sent invalid \"Content-Length\" header");
            ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
            goto failed;
        }

        if (r->headers_in.content_length_n > 0 && r->stream->in_closed) {
            ngx_log_error(NGX_LOG_INFO, fc->log, 0,
                          "client prematurely closed stream");