shrpx: Add --no-via option

If --no-via option is given, shrpx does not append to Via header
field. If Via header field is received, it is left unaltered.
This commit is contained in:
Tatsuhiro Tsujikawa 2013-01-09 22:01:25 +09:00
parent 4d1f1f2395
commit c45fa16f94
7 changed files with 56 additions and 32 deletions

View File

@ -351,6 +351,7 @@ void fill_default_config()
mod_config()->spdy_max_concurrent_streams =
SPDYLAY_INITIAL_MAX_CONCURRENT_STREAMS;
mod_config()->add_x_forwarded_for = false;
mod_config()->no_via = false;
mod_config()->accesslog = false;
set_config_str(&mod_config()->conf_path, "/etc/shrpx/shrpx.conf");
mod_config()->syslog = false;
@ -518,6 +519,9 @@ void print_help(std::ostream& out)
<< " --add-x-forwarded-for\n"
<< " Append X-Forwarded-For header field to the\n"
<< " downstream request.\n"
<< " --no-via Don't append to Via header field. If Via\n"
<< " header field is received, it is left\n"
<< " unaltered.\n"
<< " -D, --daemon Run in a background. If -D is used, the\n"
<< " current working directory is changed to '/'.\n"
<< " --pid-file=<PATH> Set path to save PID of this program.\n"
@ -575,6 +579,7 @@ int main(int argc, char **argv)
{"backend-ipv4", no_argument, &flag, 20 },
{"backend-ipv6", no_argument, &flag, 21 },
{"private-key-passwd-file", required_argument, &flag, 22},
{"no-via", no_argument, &flag, 23},
{0, 0, 0, 0 }
};
int option_index = 0;
@ -717,6 +722,10 @@ int main(int argc, char **argv)
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_PRIVATE_KEY_PASSWD_FILE,
optarg));
break;
case 23:
// --no-via
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_NO_VIA, "yes"));
break;
default:
break;
}

View File

@ -57,6 +57,7 @@ const char SHRPX_OPT_DAEMON[] = "daemon";
const char SHRPX_OPT_SPDY_PROXY[] = "spdy-proxy";
const char SHRPX_OPT_CLIENT_PROXY[] = "client-proxy";
const char SHRPX_OPT_ADD_X_FORWARDED_FOR[] = "add-x-forwarded-for";
const char SHRPX_OPT_NO_VIA[] = "no-via";
const char
SHRPX_OPT_FRONTEND_SPDY_READ_TIMEOUT[] = "frontend-spdy-read-timeout";
const char SHRPX_OPT_FRONTEND_READ_TIMEOUT[] = "frontend-read-timeout";
@ -209,6 +210,8 @@ int parse_config(const char *opt, const char *optarg)
mod_config()->client_proxy = util::strieq(optarg, "yes");
} else if(util::strieq(opt, SHRPX_OPT_ADD_X_FORWARDED_FOR)) {
mod_config()->add_x_forwarded_for = util::strieq(optarg, "yes");
} else if(util::strieq(opt, SHRPX_OPT_NO_VIA)) {
mod_config()->no_via = util::strieq(optarg, "yes");
} else if(util::strieq(opt, SHRPX_OPT_FRONTEND_SPDY_READ_TIMEOUT)) {
timeval tv = {strtol(optarg, 0, 10), 0};
mod_config()->spdy_upstream_read_timeout = tv;

View File

@ -48,6 +48,7 @@ extern const char SHRPX_OPT_DAEMON[];
extern const char SHRPX_OPT_SPDY_PROXY[];
extern const char SHRPX_OPT_CLIENT_PROXY[];
extern const char SHRPX_OPT_ADD_X_FORWARDED_FOR[];
extern const char SHRPX_OPT_NO_VIA[];
extern const char SHRPX_OPT_FRONTEND_SPDY_READ_TIMEOUT[];
extern const char SHRPX_OPT_FRONTEND_READ_TIMEOUT[];
extern const char SHRPX_OPT_FRONTEND_WRITE_TIMEOUT[];
@ -102,6 +103,7 @@ struct Config {
bool spdy_proxy;
bool client_proxy;
bool add_x_forwarded_for;
bool no_via;
bool accesslog;
size_t spdy_upstream_window_bits;
size_t spdy_downstream_window_bits;

View File

@ -129,7 +129,7 @@ int HttpDownstreamConnection::push_request_headers()
util::strieq((*i).first.c_str(), "proxy-connection")) {
continue;
}
if(util::strieq((*i).first.c_str(), "via")) {
if(!get_config()->no_via && util::strieq((*i).first.c_str(), "via")) {
via_value = (*i).second;
continue;
}
@ -171,14 +171,16 @@ int HttpDownstreamConnection::push_request_headers()
}
hdrs += "\r\n";
}
hdrs += "Via: ";
hdrs += via_value;
if(!via_value.empty()) {
hdrs += ", ";
if(!get_config()->no_via) {
hdrs += "Via: ";
if(!via_value.empty()) {
hdrs += via_value;
hdrs += ", ";
}
hdrs += http::create_via_header_value(downstream_->get_request_major(),
downstream_->get_request_minor());
hdrs += "\r\n";
}
hdrs += http::create_via_header_value(downstream_->get_request_major(),
downstream_->get_request_minor());
hdrs += "\r\n";
hdrs += "\r\n";
if(ENABLE_LOG) {

View File

@ -604,7 +604,8 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream)
util::strieq((*i).first.c_str(), "connection") ||
util:: strieq((*i).first.c_str(), "proxy-connection")) {
// These are ignored
} else if(util::strieq((*i).first.c_str(), "via")) {
} else if(!get_config()->no_via &&
util::strieq((*i).first.c_str(), "via")) {
via_value = (*i).second;
} else {
hdrs += (*i).first;
@ -627,15 +628,17 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream)
} else {
hdrs += "Connection: close\r\n";
}
hdrs += "Via: ";
hdrs += via_value;
if(!via_value.empty()) {
hdrs += ", ";
if(!get_config()->no_via) {
hdrs += "Via: ";
if(!via_value.empty()) {
hdrs += via_value;
hdrs += ", ";
}
hdrs += http::create_via_header_value
(downstream->get_response_major(), downstream->get_response_minor());
hdrs += "\r\n";
}
hdrs += http::create_via_header_value
(downstream->get_response_major(), downstream->get_response_minor());
hdrs += "\r\n";
hdrs += "\r\n";
if(ENABLE_LOG) {
const char *hdrp;

View File

@ -245,7 +245,8 @@ int SpdyDownstreamConnection::push_request_headers()
util::strieq((*i).first.c_str(), "connection") ||
util:: strieq((*i).first.c_str(), "proxy-connection")) {
// These are ignored
} else if(util::strieq((*i).first.c_str(), "via")) {
} else if(!get_config()->no_via &&
util::strieq((*i).first.c_str(), "via")) {
via_value = (*i).second;
} else if(util::strieq((*i).first.c_str(), "x-forwarded-for")) {
xff_value = (*i).second;
@ -282,14 +283,15 @@ int SpdyDownstreamConnection::push_request_headers()
nv[hdidx++] = "x-forwarded-proto";
nv[hdidx++] = "http";
}
if(!via_value.empty()) {
via_value += ", ";
if(!get_config()->no_via) {
if(!via_value.empty()) {
via_value += ", ";
}
via_value += http::create_via_header_value
(downstream_->get_request_major(), downstream_->get_request_minor());
nv[hdidx++] = "via";
nv[hdidx++] = via_value.c_str();
}
via_value += http::create_via_header_value(downstream_->get_request_major(),
downstream_->get_request_minor());
nv[hdidx++] = "via";
nv[hdidx++] = via_value.c_str();
nv[hdidx++] = 0;
if(ENABLE_LOG) {
std::stringstream ss;

View File

@ -755,20 +755,23 @@ int SpdyUpstream::on_downstream_header_complete(Downstream *downstream)
util::strieq((*i).first.c_str(), "connection") ||
util:: strieq((*i).first.c_str(), "proxy-connection")) {
// These are ignored
} else if(util::strieq((*i).first.c_str(), "via")) {
} else if(!get_config()->no_via &&
util::strieq((*i).first.c_str(), "via")) {
via_value = (*i).second;
} else {
nv[hdidx++] = (*i).first.c_str();
nv[hdidx++] = (*i).second.c_str();
}
}
if(!via_value.empty()) {
via_value += ", ";
if(!get_config()->no_via) {
if(!via_value.empty()) {
via_value += ", ";
}
via_value += http::create_via_header_value
(downstream->get_response_major(), downstream->get_response_minor());
nv[hdidx++] = "via";
nv[hdidx++] = via_value.c_str();
}
via_value += http::create_via_header_value(downstream->get_response_major(),
downstream->get_response_minor());
nv[hdidx++] = "via";
nv[hdidx++] = via_value.c_str();
nv[hdidx++] = 0;
if(ENABLE_LOG) {
std::stringstream ss;