-
Notifications
You must be signed in to change notification settings - Fork 115
fix(forward): Respond with 413 if request body too large #5630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,9 @@ impl IntoResponse for ForwardError { | |
| HttpError::Misconfigured => StatusCode::INTERNAL_SERVER_ERROR.into_response(), | ||
| }, | ||
| Self::Upstream(UpstreamRequestError::SendFailed(e)) => { | ||
| if has_source::<http_body_util::LengthLimitError>(&e) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The length limit error is deeply nested:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there another option with a different/wrapped middleware which makes this less tedious?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could possibly make this a little more flat, but the basic problem is that since we're now streaming, the error occurs in the |
||
| return StatusCode::PAYLOAD_TOO_LARGE.into_response(); | ||
| } | ||
| if e.is_timeout() { | ||
| StatusCode::GATEWAY_TIMEOUT.into_response() | ||
| } else { | ||
|
|
@@ -82,6 +85,7 @@ impl IntoResponse for ForwardError { | |
| } | ||
|
|
||
| /// A http response of a successfully forwarded request. | ||
| #[derive(Debug)] | ||
| pub struct ForwardResponse { | ||
| status: StatusCode, | ||
| headers: HeaderMap, | ||
|
|
@@ -331,3 +335,15 @@ impl ForwardRequestBuilder { | |
| Ok(tokio::time::timeout(self.timeout, self.receiver).await???) | ||
| } | ||
| } | ||
|
|
||
| /// Returns `true` if any of the error's sources matches the given type. | ||
| fn has_source<T: std::error::Error + 'static>(error: &dyn std::error::Error) -> bool { | ||
| let mut source = error.source(); | ||
| while let Some(s) = source { | ||
| if s.downcast_ref::<T>().is_some() { | ||
| return true; | ||
| } | ||
| source = s.source(); | ||
| } | ||
| false | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -301,7 +301,11 @@ def get_error_message(data): | |
| def count_hits(): | ||
| # Consume POST body even if we don't like this request | ||
| # to no clobber the socket and buffers | ||
| _ = flask_request.data | ||
| try: | ||
| _ = flask_request.data | ||
| except Exception: | ||
| # stream might be invalid | ||
| pass | ||
|
Comment on lines
+306
to
+308
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this, the integration test crashes before we see what relay responds with. |
||
|
|
||
| if flask_request.url_rule: | ||
| sentry.hit(flask_request.url_rule.rule) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,7 +247,7 @@ def test_store_allowed_origins_passes(mini_sentry, relay, allowed_origins): | |
| [ | ||
| "/api/42/store/", | ||
| "/api/42/envelope/", | ||
| "/api/666/envelope/", | ||
| "/api/42/attachment/", | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed this back to the original. By using |
||
| "/api/42/minidump/", | ||
| ], | ||
| ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this only to be able to reference the type. The dependency was already in our tree.