diff --git a/src/shrpx_http2_downstream_connection.cc b/src/shrpx_http2_downstream_connection.cc index efb2dc65..57db8141 100644 --- a/src/shrpx_http2_downstream_connection.cc +++ b/src/shrpx_http2_downstream_connection.cc @@ -366,15 +366,18 @@ int Http2DownstreamConnection::push_request_headers() { } std::string xff_value; - auto xff = req.fs.header(http2::HD_X_FORWARDED_FOR); + auto xff = get_config()->strip_incoming_x_forwarded_for + ? nullptr + : req.fs.header(http2::HD_X_FORWARDED_FOR); + if (get_config()->add_x_forwarded_for) { - if (xff && !get_config()->strip_incoming_x_forwarded_for) { + if (xff) { xff_value = (*xff).value; xff_value += ", "; } xff_value += upstream->get_client_handler()->get_ipaddr(); nva.push_back(http2::make_nv_ls("x-forwarded-for", xff_value)); - } else if (xff && !get_config()->strip_incoming_x_forwarded_for) { + } else if (xff) { nva.push_back(http2::make_nv_ls_nocopy("x-forwarded-for", (*xff).value)); } diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index 170cd4d8..4cee09e9 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -331,16 +331,19 @@ int HttpDownstreamConnection::push_request_headers() { buf->append("\r\n"); } - auto xff = req.fs.header(http2::HD_X_FORWARDED_FOR); + auto xff = get_config()->strip_incoming_x_forwarded_for + ? nullptr + : req.fs.header(http2::HD_X_FORWARDED_FOR); + if (get_config()->add_x_forwarded_for) { buf->append("X-Forwarded-For: "); - if (xff && !get_config()->strip_incoming_x_forwarded_for) { + if (xff) { buf->append((*xff).value); buf->append(", "); } buf->append(client_handler_->get_ipaddr()); buf->append("\r\n"); - } else if (xff && !get_config()->strip_incoming_x_forwarded_for) { + } else if (xff) { buf->append("X-Forwarded-For: "); buf->append((*xff).value); buf->append("\r\n");