nghttpx: Simplify xff handling

This commit is contained in:
Tatsuhiro Tsujikawa 2016-01-16 16:48:41 +09:00
parent e4816c5ba9
commit 7be0217bc0
2 changed files with 12 additions and 6 deletions

View File

@ -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));
} }

View File

@ -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");