Commit 7be0217b authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttpx: Simplify xff handling

parent e4816c5b
...@@ -366,15 +366,18 @@ int Http2DownstreamConnection::push_request_headers() { ...@@ -366,15 +366,18 @@ int Http2DownstreamConnection::push_request_headers() {
} }
std::string xff_value; 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 (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;
xff_value += ", "; xff_value += ", ";
} }
xff_value += upstream->get_client_handler()->get_ipaddr(); xff_value += upstream->get_client_handler()->get_ipaddr();
nva.push_back(http2::make_nv_ls("x-forwarded-for", xff_value)); 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)); nva.push_back(http2::make_nv_ls_nocopy("x-forwarded-for", (*xff).value));
} }
......
...@@ -331,16 +331,19 @@ int HttpDownstreamConnection::push_request_headers() { ...@@ -331,16 +331,19 @@ int HttpDownstreamConnection::push_request_headers() {
buf->append("\r\n"); 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) { if (get_config()->add_x_forwarded_for) {
buf->append("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((*xff).value);
buf->append(", "); buf->append(", ");
} }
buf->append(client_handler_->get_ipaddr()); buf->append(client_handler_->get_ipaddr());
buf->append("\r\n"); buf->append("\r\n");
} else if (xff && !get_config()->strip_incoming_x_forwarded_for) { } else if (xff) {
buf->append("X-Forwarded-For: "); buf->append("X-Forwarded-For: ");
buf->append((*xff).value); buf->append((*xff).value);
buf->append("\r\n"); buf->append("\r\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment