-
Notifications
You must be signed in to change notification settings - Fork 100
feat(playstation): Emit outcome for skipped fields #4862
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
base: master
Are you sure you want to change the base?
feat(playstation): Emit outcome for skipped fields #4862
Conversation
impl IntoResponse for BadMultipart { | ||
fn into_response(self) -> Response { | ||
let status_code = match self { | ||
BadMultipart::Multipart( | ||
multer::Error::FieldSizeExceeded { .. } | multer::Error::StreamSizeExceeded { .. }, | ||
) => StatusCode::PAYLOAD_TOO_LARGE, | ||
_ => StatusCode::BAD_REQUEST, | ||
}; | ||
|
||
(status_code, ApiErrorResponse::from_error(&self)).into_response() | ||
} | ||
} |
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.
This copies the behaviour found here:
relay/relay-server/src/extractors/remote.rs
Lines 61 to 70 in 25f09a4
fn into_response(self) -> Response { | |
let Self(ref error) = self; | |
let status_code = match error { | |
multer::Error::FieldSizeExceeded { .. } => StatusCode::PAYLOAD_TOO_LARGE, | |
multer::Error::StreamSizeExceeded { .. } => StatusCode::PAYLOAD_TOO_LARGE, | |
_ => StatusCode::BAD_REQUEST, | |
}; | |
(status_code, ApiErrorResponse::from_error(error)).into_response() |
@@ -177,7 +215,10 @@ where | |||
let content_type = field.content_type().cloned(); | |||
let field = LimitedField::new(field, config.max_attachment_size()); | |||
match field.bytes().await { | |||
Err(multer::Error::FieldSizeExceeded { .. }) if ignore_large_fields => continue, | |||
Err(multer::Error::FieldSizeExceeded { limit, .. }) if ignore_large_fields => { |
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.
Cheating here a bit by putting the consumed size into the error rather than the limit that is breached such that we can use that value to generate the outcome.
relay-server/src/utils/multipart.rs
Outdated
|quantity| { | ||
outcome_aggregator.send(TrackOutcome { | ||
timestamp: request_meta.received_at(), | ||
scoping: request_meta.get_partial_scoping(), | ||
outcome: Outcome::Invalid(DiscardReason::TooLarge( | ||
DiscardItemType::Attachment(DiscardAttachmentType::Attachment), | ||
)), | ||
event_id: None, | ||
remote_addr: request_meta.remote_addr(), | ||
category: DataCategory::Attachment, | ||
quantity, | ||
}) | ||
}, |
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 tried making this a method of UnconstrainedMultipart
but that did not work since we also need the self.multiparts
when invoking multipart_items
hence it is like this.
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.
LGTM aside from a stylistic nitpick
multipart_from_request(request, multer::Constraints::new()) | ||
.map(Self) | ||
.map_err(Remote) | ||
.map(|multipart| UnconstrainedMultipart { | ||
multipart, | ||
outcome_aggregator: state.outcome_aggregator().clone(), | ||
request_meta, | ||
}) | ||
.map_err(Into::into) |
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 think this is clearer like this:
let multipart = multipart_from_request(request, multer::Constraints::new())?;
Ok(UnconstrainedMultipart {
multipart,
outcome_aggregator: state.outcome_aggregator().clone(),
request_meta,
})
(can't make a suggestion because deleted lines)
Currently there is no communication to the user about a field being skipped. This PR adds the logic for emitting outcomes for skipped fields such that the users are aware of these skipped fields.
Follow up to: #4793