Skip to content

Commit ae78c90

Browse files
afrindmeta-codesync[bot]
authored andcommitted
Store authority/path on MoQSession
Summary: Add `authority_` and `path_` string fields to `MoQSession` with public get/set accessors. Three code paths populate them: - **WebTransport (server)**: `MoQServer::Handler::onHeadersComplete` sets them from the HTTP `Host` header and request path immediately after creating the session. - **Native QUIC (server)**: `MoQSession::onClientSetup` sets them (if not already set) from the `AUTHORITY` and `PATH` parameters in the incoming `CLIENT_SETUP` message. - **Client side**: `MoQClientBase::completeSetupMoQSession` sets them from `url_` before calling `setup()`. A `getFirstStringParam` helper is added to `MoQTypes.h`, parallel to the existing `getFirstIntParam` template, to extract string setup parameters by key. Reviewed By: sharmafb Differential Revision: D95593897 fbshipit-source-id: 6fc8436f26fac3856e3675ff5a773f0ae422ff64
1 parent a1d2716 commit ae78c90

6 files changed

Lines changed: 106 additions & 3 deletions

File tree

moxygen/MoQClientBase.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ folly::coro::Task<ServerSetup> MoQClientBase::completeSetupMoQSession(
8989
moqSession_ =
9090
createSession(folly::MaybeManagedPtr<proxygen::WebTransport>(wt));
9191

92+
moqSession_->setPath(url_.getPath());
93+
moqSession_->setAuthority(url_.getHostAndPortOmitDefault());
94+
9295
// Configure session based on negotiated ALPN
9396
// If there is no ALPN negotiation, the negotiation will be done in the
9497
// Setup messages.

moxygen/MoQServer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ void MoQServer::Handler::onHeadersComplete(
294294
clientSession_ = server_.createSession(
295295
folly::MaybeManagedPtr<proxygen::WebTransport>(wt),
296296
server_.getOrCreateExecutor(evb));
297+
clientSession_->setAuthority(
298+
std::string(req->getHeaders().getSingleOrEmpty(HTTP_HEADER_HOST)));
299+
clientSession_->setPath(std::string(req->getPathAsStringPiece()));
297300
if (server_.mLoggerFactory_) {
298301
auto logger = server_.createLogger();
299302
// Set QUIC connection IDs and addresses on the logger from the underlying

moxygen/MoQSession.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,6 +2341,18 @@ folly::coro::Task<ServerSetup> MoQSession::setup(ClientSetup setup) {
23412341

23422342
auto maxRequestID = getMaxRequestIDIfPresent(setup.params);
23432343

2344+
// Set authority/path from CLIENT_SETUP params if present
2345+
auto setupAuthority = getFirstStringParam(
2346+
setup.params, folly::to_underlying(SetupKey::AUTHORITY));
2347+
if (!setupAuthority.empty()) {
2348+
authority_ = std::move(setupAuthority);
2349+
}
2350+
auto setupPath =
2351+
getFirstStringParam(setup.params, folly::to_underlying(SetupKey::PATH));
2352+
if (!setupPath.empty()) {
2353+
path_ = std::move(setupPath);
2354+
}
2355+
23442356
if (shouldIncludeMoqtImplementationParam(setup.supportedVersions)) {
23452357
setup.params.insertParam(SetupParameter(
23462358
{folly::to_underlying(SetupKey::MOQT_IMPLEMENTATION),
@@ -2463,6 +2475,30 @@ void MoQSession::onClientSetup(ClientSetup clientSetup) {
24632475
std::min(kMaxSendTokenCacheSize, peerAuthCacheSize),
24642476
/*evict=*/true);
24652477

2478+
auto clientAuthority = getFirstStringParam(
2479+
clientSetup.params, folly::to_underlying(SetupKey::AUTHORITY));
2480+
if (!clientAuthority.empty()) {
2481+
if (!authority_.empty()) {
2482+
XLOG(ERR) << "AUTHORITY in CLIENT_SETUP conflicts with pre-set authority"
2483+
<< " sess=" << this;
2484+
close(SessionCloseErrorCode::PROTOCOL_VIOLATION);
2485+
return;
2486+
}
2487+
authority_ = std::move(clientAuthority);
2488+
}
2489+
2490+
auto clientPath = getFirstStringParam(
2491+
clientSetup.params, folly::to_underlying(SetupKey::PATH));
2492+
if (!clientPath.empty()) {
2493+
if (!path_.empty()) {
2494+
XLOG(ERR) << "PATH in CLIENT_SETUP conflicts with pre-set path"
2495+
<< " sess=" << this;
2496+
close(SessionCloseErrorCode::PROTOCOL_VIOLATION);
2497+
return;
2498+
}
2499+
path_ = std::move(clientPath);
2500+
}
2501+
24662502
auto serverSetup =
24672503
serverSetupCallback_->onClientSetup(clientSetup, shared_from_this());
24682504
if (!serverSetup.hasValue()) {

moxygen/MoQSession.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,19 @@ class MoQSession : public Subscriber,
148148
return closed_;
149149
}
150150

151+
void setAuthority(std::string a) {
152+
authority_ = std::move(a);
153+
}
154+
void setPath(std::string p) {
155+
path_ = std::move(p);
156+
}
157+
const std::string& getAuthority() const {
158+
return authority_;
159+
}
160+
const std::string& getPath() const {
161+
return path_;
162+
}
163+
151164
explicit MoQSession(
152165
folly::MaybeManagedPtr<proxygen::WebTransport> wt,
153166
std::shared_ptr<MoQExecutor> exec);
@@ -912,5 +925,7 @@ class MoQSession : public Subscriber,
912925
mutable quic::TransportInfo cachedTransportInfo_;
913926
mutable std::chrono::steady_clock::time_point lastTransportInfoUpdate_{};
914927
bool closed_{false};
928+
std::string authority_;
929+
std::string path_;
915930
};
916931
} // namespace moxygen

moxygen/MoQTypes.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,18 @@ std::optional<uint64_t> getFirstIntParam(
573573
return std::nullopt;
574574
}
575575

576+
// Helper function to extract a string parameter by key from a parameter list
577+
inline std::string getFirstStringParam(
578+
const SetupParameters& params,
579+
uint64_t key) {
580+
for (const auto& param : params) {
581+
if (param.key == key) {
582+
return param.asString;
583+
}
584+
}
585+
return {};
586+
}
587+
576588
struct ClientSetup {
577589
std::vector<uint64_t> supportedVersions;
578590
SetupParameters params{FrameType::CLIENT_SETUP};

moxygen/test/MoQSessionTests.cpp

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,45 @@ TEST(MoQSessionTest, ServerSetupVersion15WithoutAlpnShouldFail) {
186186
serverSession->close(SessionCloseErrorCode::NO_ERROR);
187187
}
188188
}
189-
CO_TEST_P_X(MoQSessionTest, Goaway) {
189+
// === AUTHORITY / PATH tests ===
190+
191+
using MoQAuthorityPathTest = MoQSessionTest;
192+
INSTANTIATE_TEST_SUITE_P(
193+
MoQAuthorityPathTest,
194+
MoQAuthorityPathTest,
195+
testing::ValuesIn(getSupportedVersionParams()));
196+
197+
// After a normal setup the server session's path should be populated from the
198+
// PATH parameter in CLIENT_SETUP, and authority should remain empty (no
199+
// AUTHORITY param is sent in the test ClientSetup).
200+
CO_TEST_P_X(MoQAuthorityPathTest, ServerSessionPathFromClientSetup) {
190201
co_await setupMoQSession();
202+
EXPECT_EQ(serverSession_->getPath(), "/foo");
203+
EXPECT_EQ(serverSession_->getAuthority(), "");
204+
clientSession_->close(SessionCloseErrorCode::NO_ERROR);
205+
}
206+
207+
// If authority/path are already set on the server session before CLIENT_SETUP
208+
// arrives (e.g. populated from HTTP Host/request-path in the WT case), a
209+
// CLIENT_SETUP that also carries PATH is a protocol violation and must close
210+
// the session.
211+
CO_TEST_P_X(MoQAuthorityPathTest, PathInClientSetupConflictsWithPreSetPath) {
212+
serverSession_->setPath("/pre-set-path");
191213

192-
// Make a SUBSCRIBE request so that we don't immediately close when goaway()
193-
// is called.
214+
clientSession_->setPublishHandler(clientPublisher);
215+
clientSession_->setSubscribeHandler(clientSubscriber);
216+
clientSession_->start();
217+
serverSession_->setPublishHandler(serverPublisher);
218+
serverSession_->setSubscribeHandler(serverSubscriber);
219+
serverSession_->start();
220+
221+
auto result = co_await folly::coro::co_awaitTry(
222+
clientSession_->setup(getClientSetup(initialMaxRequestID_)));
223+
EXPECT_TRUE(result.hasException() || serverWt_->isSessionClosed());
224+
}
225+
226+
CO_TEST_P_X(MoQSessionTest, Goaway) {
227+
co_await setupMoQSession();
194228
expectSubscribe([](auto sub, auto pub) -> TaskSubscribeResult {
195229
auto pubResult = pub->beginSubgroup(0, 0, 0);
196230
EXPECT_FALSE(pubResult.hasError());

0 commit comments

Comments
 (0)