-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: I'm making separate RateLimitFilters for each of the events (control messages, headers, direct error handling, etc) that we rate limit. This is one step of that process. Reviewed By: afrind Differential Revision: D50698700 fbshipit-source-id: c6dedc97acb090b2aecb19b1680fe65beb72add7
- Loading branch information
1 parent
d11d74f
commit 8ce3f02
Showing
2 changed files
with
58 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <proxygen/lib/http/codec/HTTP2Constants.h> | ||
#include <proxygen/lib/http/codec/RateLimitFilter.h> | ||
|
||
namespace proxygen { | ||
|
||
class HeadersRateLimitFilter : public RateLimitFilter { | ||
public: | ||
static const uint32_t kDefaultMaxEventsPerInterval = 50000; | ||
static const uint32_t kMaxEventsPerIntervalLowerBound = 100; | ||
static constexpr std::chrono::milliseconds kDefaultTimeoutDuration{100}; | ||
|
||
explicit HeadersRateLimitFilter(folly::HHWheelTimer* timer, | ||
HTTPSessionStats* httpSessionStats) | ||
: RateLimitFilter(timer, httpSessionStats) { | ||
maxEventsInInterval_ = kDefaultMaxEventsPerInterval; | ||
timeoutDuration_ = kDefaultTimeoutDuration; | ||
} | ||
|
||
void onHeadersComplete(StreamID stream, | ||
std::unique_ptr<HTTPMessage> msg) override { | ||
if (!incrementNumEventsInCurrentInterval()) { | ||
callback_->onHeadersComplete(stream, std::move(msg)); | ||
} else { | ||
callback_->onGoaway(http2::kMaxStreamID, ErrorCode::NO_ERROR); | ||
} | ||
} | ||
|
||
void recordNumEventsInCurrentInterval(uint32_t numEvents) override { | ||
if (httpSessionStats_) { | ||
httpSessionStats_->recordHeadersInInterval(numEvents); | ||
} | ||
} | ||
|
||
void recordRateLimitBreached() override { | ||
if (httpSessionStats_) { | ||
httpSessionStats_->recordHeadersRateLimited(); | ||
} | ||
} | ||
|
||
uint32_t getMaxEventsPerInvervalLowerBound() const override { | ||
return kMaxEventsPerIntervalLowerBound; | ||
} | ||
}; | ||
|
||
} // namespace proxygen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters