in proxygen/lib/http/session/HTTPSessionAcceptor.cpp [52:125]
void HTTPSessionAcceptor::onNewConnection(folly::AsyncTransport::UniquePtr sock,
const SocketAddress* peerAddress,
const string& nextProtocol,
wangle::SecureTransportType,
const wangle::TransportInfo& tinfo) {
unique_ptr<HTTPCodec> codec = codecFactory_->getCodec(
nextProtocol,
TransportDirection::DOWNSTREAM,
// we assume if security protocol isn't empty, then it's TLS
!sock->getSecurityProtocol().empty());
if (!codec) {
VLOG(2) << "codecFactory_ failed to provide codec";
onSessionCreationError(ProxygenError::kErrorUnsupportedScheme);
return;
}
auto egressSettings = codec->getEgressSettings();
if (egressSettings && setEnableConnectProtocol_) {
egressSettings->setSetting(SettingsId::ENABLE_CONNECT_PROTOCOL, 1);
}
auto controller = getController();
SocketAddress localAddress;
try {
sock->getLocalAddress(&localAddress);
} catch (...) {
VLOG(3) << "couldn't get local address for socket";
localAddress = unknownSocketAddress_;
}
// overwrite address if the socket has no IP, e.g. Unix domain socket
if (!localAddress.isFamilyInet()) {
if (accConfig_.bindAddress.isFamilyInet()) {
localAddress = accConfig_.bindAddress;
} else {
localAddress = unknownSocketAddress_;
}
VLOG(4) << "set localAddress=" << localAddress.describe();
}
auto sessionInfoCb = sessionInfoCb_ ? sessionInfoCb_ : this;
VLOG(4) << "Created new " << nextProtocol << " session for peer "
<< *peerAddress;
HTTPDownstreamSession* session =
new HTTPDownstreamSession(getTransactionTimeoutSet(),
std::move(sock),
localAddress,
*peerAddress,
controller,
std::move(codec),
tinfo,
sessionInfoCb);
if (accConfig_.maxConcurrentIncomingStreams) {
session->setMaxConcurrentIncomingStreams(
accConfig_.maxConcurrentIncomingStreams);
}
session->setEgressSettings(accConfig_.egressSettings);
// set HTTP2 priorities flag on session object
auto HTTP2PrioritiesEnabled = getHttp2PrioritiesEnabled();
session->setHTTP2PrioritiesEnabled(HTTP2PrioritiesEnabled);
// set flow control parameters
session->setFlowControl(accConfig_.initialReceiveWindow,
accConfig_.receiveStreamWindowSize,
accConfig_.receiveSessionWindowSize);
if (accConfig_.writeBufferLimit > 0) {
session->setWriteBufferLimit(accConfig_.writeBufferLimit);
}
session->setSessionStats(downstreamSessionStats_);
Acceptor::addConnection(session);
startSession(*session);
}