Skip to content

Commit

Permalink
Add Fields marking client and server error to Proxy-Headers
Browse files Browse the repository at this point in the history
Summary: Adding new fields onto the Proxy-Status header to denote what type of error the error is, in order to aid debugging

Reviewed By: jalopezsilva

Differential Revision: D51336978

fbshipit-source-id: 7051071ddfcbc3e279bf6f652b8c26fbf791bd36
  • Loading branch information
Timothy Leung authored and facebook-github-bot committed Nov 30, 2023
1 parent 6744229 commit 6119642
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
18 changes: 18 additions & 0 deletions proxygen/lib/http/ProxyStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace {
constexpr folly::StringPiece kProxyParam{"e_proxy"};
constexpr folly::StringPiece kUpstreamIPParam{"e_upip"};
constexpr folly::StringPiece kIsProxyErrorParam{"e_isproxyerr"};
constexpr folly::StringPiece kIsClientErrorTrue{"e_isclienterr"};
constexpr folly::StringPiece kIsServerErrorTrue{"e_isservererr"};
constexpr folly::StringPiece kClientAddrParam{"e_clientaddr"};

} // namespace
Expand Down Expand Up @@ -61,6 +63,22 @@ ProxyStatus& ProxyStatus::setProxyError(const bool isProxyError) {
}
}

ProxyStatus& ProxyStatus::setServerError(const bool isServerError) {
if (isServerError) {
return setProxyStatusParameter(kIsServerErrorTrue, "true");
} else {
return setProxyStatusParameter(kIsServerErrorTrue, "false");
}
}

ProxyStatus& ProxyStatus::setClientError(const bool isClientError) {
if (isClientError) {
return setProxyStatusParameter(kIsClientErrorTrue, "true");
} else {
return setProxyStatusParameter(kIsClientErrorTrue, "false");
}
}

ProxyStatus& ProxyStatus::setClientAddress(const std::string& clientAddr) {
return setProxyStatusParameter(kClientAddrParam, clientAddr);
}
Expand Down
2 changes: 2 additions & 0 deletions proxygen/lib/http/ProxyStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class ProxyStatus {
ProxyStatus& setProxy(const std::string& proxy);
ProxyStatus& setUpstreamIP(const std::string& upstreamIP);
ProxyStatus& setProxyError(const bool isProxyError);
ProxyStatus& setClientError(const bool isProxyError);
ProxyStatus& setServerError(const bool isProxyError);
ProxyStatus& setClientAddress(const std::string& clientAddr);
virtual ProxyStatus& setProxyStatusParameter(folly::StringPiece name,
const std::string& text);
Expand Down
36 changes: 36 additions & 0 deletions proxygen/lib/http/test/ProxyStatusTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,39 @@ TEST(ProxyStatusTest, TestSetProxyError) {
EXPECT_EQ(parameterisedList[0].parameterMap["e_isproxyerr"],
std::string("false"));
}

TEST(ProxyStatusTest, TestSetServerError) {
ProxyStatus proxy_status{StatusType::proxy_internal_error};
proxy_status.setServerError(true);

auto str = proxy_status.toString();
StructuredHeadersDecoder decoder(str);
StructuredHeaders::ParameterisedList parameterisedList;
decoder.decodeParameterisedList(parameterisedList);

EXPECT_EQ(parameterisedList.size(), 1);
EXPECT_EQ(parameterisedList[0].identifier, "proxy_internal_error");
EXPECT_EQ(parameterisedList[0].parameterMap.size(), 1);
EXPECT_EQ(parameterisedList[0].parameterMap["e_isservererr"].tag,
StructuredHeaderItem::Type::STRING);
EXPECT_EQ(parameterisedList[0].parameterMap["e_isservererr"],
std::string("true"));
}

TEST(ProxyStatusTest, TestSetClientError) {
ProxyStatus proxy_status{StatusType::proxy_internal_error};
proxy_status.setClientError(true);

auto str = proxy_status.toString();
StructuredHeadersDecoder decoder(str);
StructuredHeaders::ParameterisedList parameterisedList;
decoder.decodeParameterisedList(parameterisedList);

EXPECT_EQ(parameterisedList.size(), 1);
EXPECT_EQ(parameterisedList[0].identifier, "proxy_internal_error");
EXPECT_EQ(parameterisedList[0].parameterMap.size(), 1);
EXPECT_EQ(parameterisedList[0].parameterMap["e_isclienterr"].tag,
StructuredHeaderItem::Type::STRING);
EXPECT_EQ(parameterisedList[0].parameterMap["e_isclienterr"],
std::string("true"));
}

0 comments on commit 6119642

Please sign in to comment.