-
Notifications
You must be signed in to change notification settings - Fork 217
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
728 payload content-type check & error handling #738
Conversation
} | ||
|
||
private boolean isOfType(String contentType, String expectedContentType, String expectedWithDelim) { | ||
return contentType != null && (contentType.length() > expectedContentType.length() ? |
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.
shouldn't we just check startsWith
?
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.
also, content type is not case sensitive (https://www.w3.org/Protocols/rfc1341/4_Content-Type.html) so we can match with String.toLowerCase
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.
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?
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.
no, the current algorithm is fine
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.
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) { |
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.
why Avro Schema here? i don't get it, we probably want topic name, not schema name
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.
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() ? |
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.
no, the current algorithm is fine
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