nghttpx: Omit Forwarded for and by parameter if UNIX domain socket is used

This commit is contained in:
Tatsuhiro Tsujikawa 2016-01-19 23:26:04 +09:00
parent acb38b726f
commit db8de490a0
6 changed files with 32 additions and 13 deletions

View File

@ -1133,6 +1133,13 @@ const std::string &ClientHandler::get_forwarded_by() {
return local_hostport_;
}
auto &listenerconf = get_config()->conn.listener;
// For UNIX domain socket listener, just return empty string.
if (listenerconf.host_unix) {
return local_hostport_;
}
int rv;
sockaddr_union su;
socklen_t addrlen = sizeof(su);
@ -1158,7 +1165,7 @@ const std::string &ClientHandler::get_forwarded_by() {
local_hostport_ += ':';
}
local_hostport_ += util::utos(get_config()->conn.listener.port);
local_hostport_ += util::utos(listenerconf.port);
return local_hostport_;
}
@ -1168,6 +1175,10 @@ const std::string &ClientHandler::get_forwarded_for() const {
return forwarded_for_obfuscated_;
}
if (get_config()->conn.listener.host_unix) {
return EMPTY_STRING;
}
return ipaddr_;
}

View File

@ -146,6 +146,8 @@ private:
ev_timer reneg_shutdown_timer_;
std::unique_ptr<Upstream> upstream_;
std::unique_ptr<std::vector<ssize_t>> pinned_http2sessions_;
// IP address of client. If UNIX domain socket is used, this is
// "localhost".
std::string ipaddr_;
std::string port_;
// The ALPN identifier negotiated for this connection.

View File

@ -71,6 +71,8 @@ Config *mod_config() { return config; }
void create_config() { config = new Config(); }
std::string EMPTY_STRING;
TicketKeys::~TicketKeys() {
/* Erase keys from memory */
for (auto &key : keys) {

View File

@ -227,6 +227,10 @@ enum shrpx_forwarded_node_type {
FORWARDED_NODE_IP,
};
// Used inside function if it has to return const reference to empty
// string without defining empty string each time.
extern std::string EMPTY_STRING;
struct AltSvc {
AltSvc() : port(0) {}

View File

@ -698,14 +698,10 @@ bool Downstream::get_http2_upgrade_request() const {
response_state_ == INITIAL;
}
namespace {
const std::string EMPTY;
} // namespace
const std::string &Downstream::get_http2_settings() const {
auto http2_settings = req_.fs.header(http2::HD_HTTP2_SETTINGS);
if (!http2_settings) {
return EMPTY;
return EMPTY_STRING;
}
return http2_settings->value;
}

View File

@ -751,15 +751,19 @@ ClientHandler *accept_connection(Worker *worker, int fd, sockaddr *addr,
char host[NI_MAXHOST];
char service[NI_MAXSERV];
int rv;
rv = getnameinfo(addr, addrlen, host, sizeof(host), service, sizeof(service),
NI_NUMERICHOST | NI_NUMERICSERV);
if (addr->sa_family == AF_UNIX) {
std::copy_n("localhost", sizeof("localhost"), host);
service[0] = '\0';
} else {
rv = getnameinfo(addr, addrlen, host, sizeof(host), service,
sizeof(service), NI_NUMERICHOST | NI_NUMERICSERV);
if (rv != 0) {
LOG(ERROR) << "getnameinfo() failed: " << gai_strerror(rv);
return nullptr;
}
if (addr->sa_family != AF_UNIX) {
rv = util::make_socket_nodelay(fd);
if (rv == -1) {
LOG(WARN) << "Setting option TCP_NODELAY failed: errno=" << errno;