Skip to content
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

728 payload content-type check & error handling #738

Merged
merged 3 commits into from
Mar 14, 2017

Conversation

rprzystasz
Copy link
Contributor

Added check which accepts only "binary/avro" or "application/json" message content-type.
In other cases, http status 400 and proper error message will be returned.

#728

}

private boolean isOfType(String contentType, String expectedContentType, String expectedWithDelim) {
return contentType != null && (contentType.length() > expectedContentType.length() ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we just check startsWith?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, content type is not case sensitive (https://www.w3.org/Protocols/rfc1341/4_Content-Type.html) so we can match with String.toLowerCase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checking with startsWith doesn't enforce ';' to be the first character after content-type value.
It would accept values like 'application/jsonANYTEXT'
Do we want to allow such values?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, the current algorithm is fine

Copy link
Contributor

@chemicL chemicL Mar 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.
We can still simplify the check

contentType != null && (contentType.equals(expectedContentType)) || contentType.startsWith(expectedWithDelim))

String.equals has a check for length.

@@ -22,4 +23,12 @@ public UnsupportedContentTypeException(Subscription subscription) {
));
}

public UnsupportedContentTypeException(String payloadContentType, Schema schema) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why Avro Schema here? i don't get it, we probably want topic name, not schema name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. In most cases schema name matches topic name, and tests didn't catch that typo.
Fixed

}

private boolean isOfType(String contentType, String expectedContentType, String expectedWithDelim) {
return contentType != null && (contentType.length() > expectedContentType.length() ?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, the current algorithm is fine

@adamdubiel adamdubiel merged commit e304e84 into allegro:develop Mar 14, 2017
@adamdubiel adamdubiel added this to the 0.11.2 milestone Mar 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants