Skip to content

Commit cbf3dcd

Browse files
hanidamlajmeta-codesync[bot]
authored andcommitted
add HTTPMessage::isConnectUdpReq
Summary: adds an HTTPMessage::isConnectUdpReq * added to consolidate all code that checks if a request is `connect-udp` into the new HTTPMessage::isConnectUdpReq * prerequisite for removing HTTPMethod::CONNECT_UDP safely (see next diffs) Reviewed By: lnicco Differential Revision: D102534951 fbshipit-source-id: 2216991800aeae6464d0317e1a71df18605dce73
1 parent 39bcb45 commit cbf3dcd

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

proxygen/lib/http/HTTPMessage.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,17 @@ const char* HTTPMessage::getDefaultReason(uint16_t status) {
991991
return "-";
992992
}
993993

994+
bool HTTPMessage::isConnectUdpReq() const noexcept {
995+
if (!isRequest()) {
996+
return false;
997+
}
998+
const auto* upgradeProto = getUpgradeProtocol();
999+
const auto method = getMethod();
1000+
return method == HTTPMethod::CONNECT_UDP ||
1001+
(method == HTTPMethod::CONNECT && upgradeProto &&
1002+
*upgradeProto == headers::kConnectUdp);
1003+
}
1004+
9941005
ParseURL HTTPMessage::setURLImplInternal(bool unparse, bool strict) {
9951006
auto& req = request();
9961007
auto u = ParseURL::parseURLMaybeInvalid(req.url_, strict);

proxygen/lib/http/HTTPMessage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,9 @@ class HTTPMessage {
861861
return fields_.which_ == MessageType::RESPONSE;
862862
}
863863

864+
// @returns true if this HTTPMessage represents a connect-udp request
865+
bool isConnectUdpReq() const noexcept;
866+
864867
/**
865868
* Assuming input contains
866869
* <name><valueDelim><value>(<pairDelim><name><valueDelim><value>),

proxygen/lib/http/HeaderConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ extern const std::string kStatus200;
2828

2929
constexpr std::string_view kWTAvailableProtocols{"wt-available-protocols"};
3030
constexpr std::string_view kWTProtocol{"wt-protocol"};
31+
constexpr std::string_view kConnectUdp{"connect-udp"};
3132

3233
} // namespace proxygen::headers

proxygen/lib/http/session/HTTPTransaction.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ inline ErrorCode getDefaultAbortErrorCode(bool isUpstream) {
4747
return isUpstream ? ErrorCode::CANCEL : ErrorCode::INTERNAL_ERROR;
4848
}
4949

50-
bool isConnectUdp(const HTTPMessage& msg) noexcept {
51-
return msg.getMethod() == HTTPMethod::CONNECT && msg.getUpgradeProtocol() &&
52-
*msg.getUpgradeProtocol() == "connect-udp";
53-
}
54-
5550
} // namespace
5651

5752
#define INVARIANT_RETURN(X, Y) \
@@ -222,7 +217,7 @@ void HTTPTransaction::onIngressHeadersComplete(
222217
headRequest_ = (method == HTTPMethod::HEAD);
223218
upgraded_ = (method == HTTPMethod::CONNECT);
224219
wtConnectStream_ = HTTPWebTransport::isConnectMessage(*msg);
225-
connectUdpStream_ = isConnectUdp(*msg);
220+
connectUdpStream_ = msg->isConnectUdpReq();
226221
}
227222

228223
if ((msg->isRequest() && msg->getMethod() != HTTPMethod::CONNECT) ||
@@ -1033,7 +1028,7 @@ void HTTPTransaction::sendHeadersWithOptionalEOM(const HTTPMessage& headers,
10331028
if (headers.isRequest()) {
10341029
headRequest_ = (headers.getMethod() == HTTPMethod::HEAD);
10351030
wtConnectStream_ = HTTPWebTransport::isConnectMessage(headers);
1036-
connectUdpStream_ = isConnectUdp(headers);
1031+
connectUdpStream_ = headers.isConnectUdpReq();
10371032
} else {
10381033
has1xxResponse_ = headers.is1xxResponse();
10391034
}

0 commit comments

Comments
 (0)