Skip to content

Commit

Permalink
add optional ErrorCode to ResponseHandler::sendAbort
Browse files Browse the repository at this point in the history
Summary: Recent diff stack (D58553215) added a new HTTPTransaction::sendAbort(ErrorCode) api. Consequently this diff exposes the api to the necessary wrappers, enabling ResponseHandler to send a RST_STREAM frame with any ErrorCode.

Reviewed By: mofa28

Differential Revision: D61485775

fbshipit-source-id: c76e28884253eb329f7835b011acd2c9495e4af2
  • Loading branch information
hanidamlaj authored and facebook-github-bot committed Sep 17, 2024
1 parent dd51644 commit fcaf06e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions proxygen/httpserver/Filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class Filter
downstream_->sendEOM();
}

void sendAbort() noexcept override {
downstream_->sendAbort();
void sendAbort(folly::Optional<ErrorCode> errorCode) noexcept override {
downstream_->sendAbort(errorCode);
}

void refreshTimeout() noexcept override {
Expand Down
5 changes: 4 additions & 1 deletion proxygen/httpserver/Mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class MockResponseHandler : public ResponseHandler {
MOCK_METHOD((void), pauseIngress, (), (noexcept));
MOCK_METHOD((void), refreshTimeout, (), (noexcept));
MOCK_METHOD((void), resumeIngress, (), (noexcept));
MOCK_METHOD((void), sendAbort, (), (noexcept));
MOCK_METHOD((void),
sendAbort,
(folly::Optional<ErrorCode> errorCode),
(noexcept));
MOCK_METHOD((void), sendBody, (std::shared_ptr<folly::IOBuf>), (noexcept));
MOCK_METHOD((void), sendChunkHeader, (size_t), (noexcept));
MOCK_METHOD((void), sendChunkTerminator, (), (noexcept));
Expand Down
13 changes: 9 additions & 4 deletions proxygen/httpserver/RequestHandlerAdaptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void RequestHandlerAdaptor::onError(const HTTPException& error) noexcept {
setError(kErrorTimeout);

if (!txn_->canSendHeaders()) {
sendAbort();
sendAbort(folly::none);
} else {
ResponseBuilder(this)
.status(408, "Request Timeout")
Expand All @@ -120,7 +120,7 @@ void RequestHandlerAdaptor::onError(const HTTPException& error) noexcept {
setError(kErrorRead);

if (!txn_->canSendHeaders()) {
sendAbort();
sendAbort(folly::none);
} else {
ResponseBuilder(this)
.status(400, "Bad Request")
Expand Down Expand Up @@ -185,8 +185,13 @@ void RequestHandlerAdaptor::sendEOM() noexcept {
txn_->sendEOM();
}

void RequestHandlerAdaptor::sendAbort() noexcept {
txn_->sendAbort();
void RequestHandlerAdaptor::sendAbort(
folly::Optional<ErrorCode> errorCode) noexcept {
if (errorCode.has_value()) {
txn_->sendAbort(errorCode.value());
} else {
txn_->sendAbort();
}
}

void RequestHandlerAdaptor::refreshTimeout() noexcept {
Expand Down
2 changes: 1 addition & 1 deletion proxygen/httpserver/RequestHandlerAdaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class RequestHandlerAdaptor
void sendBody(std::unique_ptr<folly::IOBuf> body) noexcept override;
void sendChunkTerminator() noexcept override;
void sendEOM() noexcept override;
void sendAbort() noexcept override;
void sendAbort(folly::Optional<ErrorCode> errorCode) noexcept override;
void refreshTimeout() noexcept override;
void pauseIngress() noexcept override;
void resumeIngress() noexcept override;
Expand Down
3 changes: 2 additions & 1 deletion proxygen/httpserver/ResponseHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class ResponseHandler {

virtual void sendEOM() noexcept = 0;

virtual void sendAbort() noexcept = 0;
virtual void sendAbort(
folly::Optional<ErrorCode> errorCode = folly::none) noexcept = 0;

virtual void refreshTimeout() noexcept = 0;

Expand Down
2 changes: 1 addition & 1 deletion proxygen/httpserver/filters/CompressionFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class CompressionFilter : public Filter {

protected:
void fail() {
Filter::sendAbort();
Filter::sendAbort(folly::none);
}

std::unique_ptr<HTTPMessage> responseMessage_;
Expand Down
2 changes: 1 addition & 1 deletion proxygen/httpserver/filters/RejectConnectFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class RejectConnectFilter : public Filter {
void sendEOM() noexcept override {
}

void sendAbort() noexcept override {
void sendAbort(folly::Optional<ErrorCode>) noexcept override {
}

void refreshTimeout() noexcept override {
Expand Down

0 comments on commit fcaf06e

Please sign in to comment.