shrpx: Relay Connection: upgrade header field for HTTP/1.1 connections

This commit is contained in:
Tatsuhiro Tsujikawa 2013-02-01 23:30:12 +09:00
parent d9611e65ac
commit ae0533334c
2 changed files with 16 additions and 4 deletions

View File

@ -118,14 +118,18 @@ int HttpDownstreamConnection::push_request_headers()
hdrs += downstream_->get_request_path();
hdrs += " ";
hdrs += "HTTP/1.1\r\n";
bool connection_upgrade = false;
std::string via_value;
std::string xff_value;
const Headers& request_headers = downstream_->get_request_headers();
for(Headers::const_iterator i = request_headers.begin();
i != request_headers.end(); ++i) {
if(util::strieq((*i).first.c_str(), "X-Forwarded-Proto") ||
if(util::strieq((*i).first.c_str(), "connection")) {
if(util::strifind((*i).second.c_str(), "upgrade")) {
connection_upgrade = true;
}
} else if(util::strieq((*i).first.c_str(), "X-Forwarded-Proto") ||
util::strieq((*i).first.c_str(), "keep-alive") ||
util::strieq((*i).first.c_str(), "connection") ||
util::strieq((*i).first.c_str(), "proxy-connection")) {
continue;
}
@ -149,6 +153,8 @@ int HttpDownstreamConnection::push_request_headers()
}
if(downstream_->get_request_connection_close()) {
hdrs += "Connection: close\r\n";
} else if(connection_upgrade) {
hdrs += "Connection: upgrade\r\n";
}
if(get_config()->add_x_forwarded_for) {
hdrs += "X-Forwarded-For: ";

View File

@ -594,6 +594,7 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream)
if(LOG_ENABLED(INFO)) {
DLOG(INFO, downstream) << "HTTP response header completed";
}
bool connection_upgrade = false;
std::string via_value;
char temp[16];
snprintf(temp, sizeof(temp), "HTTP/%d.%d ",
@ -604,8 +605,11 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream)
hdrs += "\r\n";
for(Headers::const_iterator i = downstream->get_response_headers().begin();
i != downstream->get_response_headers().end(); ++i) {
if(util::strieq((*i).first.c_str(), "keep-alive") || // HTTP/1.0?
util::strieq((*i).first.c_str(), "connection") ||
if(util::strieq((*i).first.c_str(), "connection")) {
if(util::strifind((*i).second.c_str(), "upgrade")) {
connection_upgrade = true;
}
} else if(util::strieq((*i).first.c_str(), "keep-alive") || // HTTP/1.0?
util:: strieq((*i).first.c_str(), "proxy-connection")) {
// These are ignored
} else if(!get_config()->no_via &&
@ -628,6 +632,8 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream)
downstream->get_request_minor() <= 0) {
// We add this header for HTTP/1.0 or HTTP/0.9 clients
hdrs += "Connection: Keep-Alive\r\n";
} else if(connection_upgrade) {
hdrs += "Connection: upgrade\r\n";
}
} else {
hdrs += "Connection: close\r\n";