mirror of
https://github.com/moparisthebest/spdylay
synced 2024-12-22 07:38:52 -05:00
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:
parent
4d1f1f2395
commit
c45fa16f94
@ -351,6 +351,7 @@ void fill_default_config()
|
|||||||
mod_config()->spdy_max_concurrent_streams =
|
mod_config()->spdy_max_concurrent_streams =
|
||||||
SPDYLAY_INITIAL_MAX_CONCURRENT_STREAMS;
|
SPDYLAY_INITIAL_MAX_CONCURRENT_STREAMS;
|
||||||
mod_config()->add_x_forwarded_for = false;
|
mod_config()->add_x_forwarded_for = false;
|
||||||
|
mod_config()->no_via = false;
|
||||||
mod_config()->accesslog = false;
|
mod_config()->accesslog = false;
|
||||||
set_config_str(&mod_config()->conf_path, "/etc/shrpx/shrpx.conf");
|
set_config_str(&mod_config()->conf_path, "/etc/shrpx/shrpx.conf");
|
||||||
mod_config()->syslog = false;
|
mod_config()->syslog = false;
|
||||||
@ -518,6 +519,9 @@ void print_help(std::ostream& out)
|
|||||||
<< " --add-x-forwarded-for\n"
|
<< " --add-x-forwarded-for\n"
|
||||||
<< " Append X-Forwarded-For header field to the\n"
|
<< " Append X-Forwarded-For header field to the\n"
|
||||||
<< " downstream request.\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"
|
<< " -D, --daemon Run in a background. If -D is used, the\n"
|
||||||
<< " current working directory is changed to '/'.\n"
|
<< " current working directory is changed to '/'.\n"
|
||||||
<< " --pid-file=<PATH> Set path to save PID of this program.\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-ipv4", no_argument, &flag, 20 },
|
||||||
{"backend-ipv6", no_argument, &flag, 21 },
|
{"backend-ipv6", no_argument, &flag, 21 },
|
||||||
{"private-key-passwd-file", required_argument, &flag, 22},
|
{"private-key-passwd-file", required_argument, &flag, 22},
|
||||||
|
{"no-via", no_argument, &flag, 23},
|
||||||
{0, 0, 0, 0 }
|
{0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
int option_index = 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,
|
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_PRIVATE_KEY_PASSWD_FILE,
|
||||||
optarg));
|
optarg));
|
||||||
break;
|
break;
|
||||||
|
case 23:
|
||||||
|
// --no-via
|
||||||
|
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_NO_VIA, "yes"));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ const char SHRPX_OPT_DAEMON[] = "daemon";
|
|||||||
const char SHRPX_OPT_SPDY_PROXY[] = "spdy-proxy";
|
const char SHRPX_OPT_SPDY_PROXY[] = "spdy-proxy";
|
||||||
const char SHRPX_OPT_CLIENT_PROXY[] = "client-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_ADD_X_FORWARDED_FOR[] = "add-x-forwarded-for";
|
||||||
|
const char SHRPX_OPT_NO_VIA[] = "no-via";
|
||||||
const char
|
const char
|
||||||
SHRPX_OPT_FRONTEND_SPDY_READ_TIMEOUT[] = "frontend-spdy-read-timeout";
|
SHRPX_OPT_FRONTEND_SPDY_READ_TIMEOUT[] = "frontend-spdy-read-timeout";
|
||||||
const char SHRPX_OPT_FRONTEND_READ_TIMEOUT[] = "frontend-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");
|
mod_config()->client_proxy = util::strieq(optarg, "yes");
|
||||||
} else if(util::strieq(opt, SHRPX_OPT_ADD_X_FORWARDED_FOR)) {
|
} else if(util::strieq(opt, SHRPX_OPT_ADD_X_FORWARDED_FOR)) {
|
||||||
mod_config()->add_x_forwarded_for = util::strieq(optarg, "yes");
|
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)) {
|
} else if(util::strieq(opt, SHRPX_OPT_FRONTEND_SPDY_READ_TIMEOUT)) {
|
||||||
timeval tv = {strtol(optarg, 0, 10), 0};
|
timeval tv = {strtol(optarg, 0, 10), 0};
|
||||||
mod_config()->spdy_upstream_read_timeout = tv;
|
mod_config()->spdy_upstream_read_timeout = tv;
|
||||||
|
@ -48,6 +48,7 @@ extern const char SHRPX_OPT_DAEMON[];
|
|||||||
extern const char SHRPX_OPT_SPDY_PROXY[];
|
extern const char SHRPX_OPT_SPDY_PROXY[];
|
||||||
extern const char SHRPX_OPT_CLIENT_PROXY[];
|
extern const char SHRPX_OPT_CLIENT_PROXY[];
|
||||||
extern const char SHRPX_OPT_ADD_X_FORWARDED_FOR[];
|
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_SPDY_READ_TIMEOUT[];
|
||||||
extern const char SHRPX_OPT_FRONTEND_READ_TIMEOUT[];
|
extern const char SHRPX_OPT_FRONTEND_READ_TIMEOUT[];
|
||||||
extern const char SHRPX_OPT_FRONTEND_WRITE_TIMEOUT[];
|
extern const char SHRPX_OPT_FRONTEND_WRITE_TIMEOUT[];
|
||||||
@ -102,6 +103,7 @@ struct Config {
|
|||||||
bool spdy_proxy;
|
bool spdy_proxy;
|
||||||
bool client_proxy;
|
bool client_proxy;
|
||||||
bool add_x_forwarded_for;
|
bool add_x_forwarded_for;
|
||||||
|
bool no_via;
|
||||||
bool accesslog;
|
bool accesslog;
|
||||||
size_t spdy_upstream_window_bits;
|
size_t spdy_upstream_window_bits;
|
||||||
size_t spdy_downstream_window_bits;
|
size_t spdy_downstream_window_bits;
|
||||||
|
@ -129,7 +129,7 @@ int HttpDownstreamConnection::push_request_headers()
|
|||||||
util::strieq((*i).first.c_str(), "proxy-connection")) {
|
util::strieq((*i).first.c_str(), "proxy-connection")) {
|
||||||
continue;
|
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;
|
via_value = (*i).second;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -171,14 +171,16 @@ int HttpDownstreamConnection::push_request_headers()
|
|||||||
}
|
}
|
||||||
hdrs += "\r\n";
|
hdrs += "\r\n";
|
||||||
}
|
}
|
||||||
|
if(!get_config()->no_via) {
|
||||||
hdrs += "Via: ";
|
hdrs += "Via: ";
|
||||||
hdrs += via_value;
|
|
||||||
if(!via_value.empty()) {
|
if(!via_value.empty()) {
|
||||||
|
hdrs += via_value;
|
||||||
hdrs += ", ";
|
hdrs += ", ";
|
||||||
}
|
}
|
||||||
hdrs += http::create_via_header_value(downstream_->get_request_major(),
|
hdrs += http::create_via_header_value(downstream_->get_request_major(),
|
||||||
downstream_->get_request_minor());
|
downstream_->get_request_minor());
|
||||||
hdrs += "\r\n";
|
hdrs += "\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
hdrs += "\r\n";
|
hdrs += "\r\n";
|
||||||
if(ENABLE_LOG) {
|
if(ENABLE_LOG) {
|
||||||
|
@ -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(), "connection") ||
|
||||||
util:: strieq((*i).first.c_str(), "proxy-connection")) {
|
util:: strieq((*i).first.c_str(), "proxy-connection")) {
|
||||||
// These are ignored
|
// 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;
|
via_value = (*i).second;
|
||||||
} else {
|
} else {
|
||||||
hdrs += (*i).first;
|
hdrs += (*i).first;
|
||||||
@ -627,15 +628,17 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream)
|
|||||||
} else {
|
} else {
|
||||||
hdrs += "Connection: close\r\n";
|
hdrs += "Connection: close\r\n";
|
||||||
}
|
}
|
||||||
|
if(!get_config()->no_via) {
|
||||||
hdrs += "Via: ";
|
hdrs += "Via: ";
|
||||||
hdrs += via_value;
|
|
||||||
if(!via_value.empty()) {
|
if(!via_value.empty()) {
|
||||||
|
hdrs += via_value;
|
||||||
hdrs += ", ";
|
hdrs += ", ";
|
||||||
}
|
}
|
||||||
hdrs += http::create_via_header_value
|
hdrs += http::create_via_header_value
|
||||||
(downstream->get_response_major(), downstream->get_response_minor());
|
(downstream->get_response_major(), downstream->get_response_minor());
|
||||||
hdrs += "\r\n";
|
hdrs += "\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
hdrs += "\r\n";
|
hdrs += "\r\n";
|
||||||
if(ENABLE_LOG) {
|
if(ENABLE_LOG) {
|
||||||
const char *hdrp;
|
const char *hdrp;
|
||||||
|
@ -245,7 +245,8 @@ int SpdyDownstreamConnection::push_request_headers()
|
|||||||
util::strieq((*i).first.c_str(), "connection") ||
|
util::strieq((*i).first.c_str(), "connection") ||
|
||||||
util:: strieq((*i).first.c_str(), "proxy-connection")) {
|
util:: strieq((*i).first.c_str(), "proxy-connection")) {
|
||||||
// These are ignored
|
// 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;
|
via_value = (*i).second;
|
||||||
} else if(util::strieq((*i).first.c_str(), "x-forwarded-for")) {
|
} else if(util::strieq((*i).first.c_str(), "x-forwarded-for")) {
|
||||||
xff_value = (*i).second;
|
xff_value = (*i).second;
|
||||||
@ -282,14 +283,15 @@ int SpdyDownstreamConnection::push_request_headers()
|
|||||||
nv[hdidx++] = "x-forwarded-proto";
|
nv[hdidx++] = "x-forwarded-proto";
|
||||||
nv[hdidx++] = "http";
|
nv[hdidx++] = "http";
|
||||||
}
|
}
|
||||||
|
if(!get_config()->no_via) {
|
||||||
if(!via_value.empty()) {
|
if(!via_value.empty()) {
|
||||||
via_value += ", ";
|
via_value += ", ";
|
||||||
}
|
}
|
||||||
via_value += http::create_via_header_value(downstream_->get_request_major(),
|
via_value += http::create_via_header_value
|
||||||
downstream_->get_request_minor());
|
(downstream_->get_request_major(), downstream_->get_request_minor());
|
||||||
nv[hdidx++] = "via";
|
nv[hdidx++] = "via";
|
||||||
nv[hdidx++] = via_value.c_str();
|
nv[hdidx++] = via_value.c_str();
|
||||||
|
}
|
||||||
nv[hdidx++] = 0;
|
nv[hdidx++] = 0;
|
||||||
if(ENABLE_LOG) {
|
if(ENABLE_LOG) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
@ -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(), "connection") ||
|
||||||
util:: strieq((*i).first.c_str(), "proxy-connection")) {
|
util:: strieq((*i).first.c_str(), "proxy-connection")) {
|
||||||
// These are ignored
|
// 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;
|
via_value = (*i).second;
|
||||||
} else {
|
} else {
|
||||||
nv[hdidx++] = (*i).first.c_str();
|
nv[hdidx++] = (*i).first.c_str();
|
||||||
nv[hdidx++] = (*i).second.c_str();
|
nv[hdidx++] = (*i).second.c_str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!get_config()->no_via) {
|
||||||
if(!via_value.empty()) {
|
if(!via_value.empty()) {
|
||||||
via_value += ", ";
|
via_value += ", ";
|
||||||
}
|
}
|
||||||
via_value += http::create_via_header_value(downstream->get_response_major(),
|
via_value += http::create_via_header_value
|
||||||
downstream->get_response_minor());
|
(downstream->get_response_major(), downstream->get_response_minor());
|
||||||
nv[hdidx++] = "via";
|
nv[hdidx++] = "via";
|
||||||
nv[hdidx++] = via_value.c_str();
|
nv[hdidx++] = via_value.c_str();
|
||||||
|
}
|
||||||
nv[hdidx++] = 0;
|
nv[hdidx++] = 0;
|
||||||
if(ENABLE_LOG) {
|
if(ENABLE_LOG) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
Loading…
Reference in New Issue
Block a user