Repository: nginx/nginx
File: src/http/modules/ngx_http_proxy_module.c (C)

Code before:
                continue;
            }

            hh = ngx_hash_find(&umcf->headers_in_hash, h->hash,
                               h->lowcase_key, h->key.len);

            if (hh) {
                rc = hh->handler(r, h, hh->offset);

                if (rc != NGX_OK) {
                    return rc;
                }
            }

            continue;
        }

        if (rc == NGX_HTTP_PARSE_HEADER_DONE) {

            /* a whole header has been parsed successfully */

            ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                           "http proxy header done");

            if (r->upstream->headers_in.status_n == NGX_HTTP_EARLY_HINTS) {
                if (ngx_http_proxy_reinit_request(r) != NGX_OK) {
                    return NGX_ERROR;
                }

                return NGX_OK;
            }

            /*
             * if no "Server" and "Date" in header line,
             * then add the special empty headers
             */

            if (r->upstream->headers_in.server == NULL) {
                h = ngx_list_push(&r->upstream->headers_in.headers);
                if (h == NULL) {
                    return NGX_ERROR;
                }

                h->hash = ngx_hash(ngx_hash(ngx_hash(ngx_hash(
                                    ngx_hash('s', 'e'), 'r'), 'v'), 'e'), 'r');

                ngx_str_set(&h->key, "Server");
                ngx_str_null(&h->value);
                h->lowcase_key = (u_char *) "server";
                h->next = NULL;
            }

Review comment (suggestion):
Since we already process early hints separately, it's probably better to do the necessary part of `ngx_http_proxy_reinit_request()` here instead of calling it.

Code after:
                continue;
            }

            hh = ngx_hash_find(&umcf->headers_in_hash, h->hash,
                               h->lowcase_key, h->key.len);

            if (hh) {
                rc = hh->handler(r, h, hh->offset);

                if (rc != NGX_OK) {
                    return rc;
                }
            }

            continue;
        }

        if (rc == NGX_HTTP_PARSE_HEADER_DONE) {

            /* a whole header has been parsed successfully */

            ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                           "http proxy header done");

            ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module);

            if (r->upstream->headers_in.status_n == NGX_HTTP_EARLY_HINTS) {
                ctx->status.code = 0;
                ctx->status.count = 0;
                ctx->status.start = NULL;
                ctx->status.end = NULL;

                r->upstream->process_header =
                                            ngx_http_proxy_process_status_line;
                r->state = 0;
                return NGX_HTTP_UPSTREAM_EARLY_HINTS;
            }

            /*
             * if no "Server" and "Date" in header line,
             * then add the special empty headers
             */

            if (r->upstream->headers_in.server == NULL) {
                h = ngx_list_push(&r->upstream->headers_in.headers);
                if (h == NULL) {
                    return NGX_ERROR;
                }

                h->hash = ngx_hash(ngx_hash(ngx_hash(ngx_hash(
                                    ngx_hash('s', 'e'), 'r'), 'v'), 'e'), 'r');