-
Notifications
You must be signed in to change notification settings - Fork 264
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
Fix when request body is empty string #1163
Conversation
Under which circumstances? We do check on the |
GET requests have |
But that's an illegal statement in HTTP. |
I totally agree that the problem is not in the Logbook, but IMHO it must be protected from IllegalArgumentException. The call workflow is as follows: I don't know where this content type header is added, but it causes us problems |
Agreed. Instead of checking for this particular issue (empty body), why not catch any exception from the JSON parser and handle that (by not doing something). That way we also covered syntactically incorrect JSON bodies, etc. |
This exception also happens when the WithoutBodyStrategy is active. It's not limited to GET requests, PUT and POST requests are also broken. This results in the following exception
|
If the body is incorrect JSON, we never execute this code. The corner case is when the body does not exist and Spring treats it as an empty string. |
@ChristianHersevoort Spot-on observation! @ismail2ov What about this then:
|
This solves our problem
This case will never occur because we already know that it is a valid JSON |
Not really. A faulty client could set |
Also application/json isn't the only content-type that is valid json!
|
@ChristianHersevoort You're right, that's also what's implemented in Logbook: logbook/logbook-json/src/main/java/org/zalando/logbook/json/JsonMediaType.java Lines 10 to 35 in 1a3fe4e
Since my comment wasn't specifically about this, hence I simplified things a bit. |
@ChristianHersevoort In this case, the Content Type is not important, it is important that if the body is an empty string, the code in the IF should not be executed |
@whiskeysierra Can we merge this as a temporary solution? This is a blocker for us.
IMHO this is very expensive and does not make sense |
How is that expensive? The exception would be thrown anyway. It's a question about invasiveness of Logbook. We try to not change the behavior of the application that is instrumented with Logbook. Catching exceptions there would be very much in line with that. |
The question is more about the design.
Right now Logbook is breaking requests. |
I don't understand how catching the exception is the ideal solution, but maybe it can be used as temporary fix.
|
I totally agree with @ChristianHersevoort |
Ideally yes, but in order to catch every single invalid input that would make the parser fail you'd need to implement the same parser again... Empty inputs are just one of endless possibilities of invalid inputs.
Exactly, and it very much should not.
I'm fine with handling empty bodies separately.
We're not using exceptions for control flows in tight loops and we don't throw exceptions where there wasn't one being thrown to begin with. So I don't see how the performance argument can be made here.
You really gotta see the empty body in the bigger picture here. An application should react to requests in the very same way, regardless of whether it's instrumented with Logbook or not.
(Hopefully in the) Future: The principle is not violated.
However, that does not mean we should not also do catch exceptions, because:
|
@whiskeysierra Part 1: (this) hotfix , only fixing this specific issue in the JsonPathBodyFilters. Ignoring (semi) unrelated content issues Part 2. Refactor of how BodyFiltering works; This will probably be a major (breaking) change. |
@whiskeysierra I totally agree with you. What do you think of this approach? I'm logging only the class name of the exception to avoid problems if the exception is NPE |
👍 |
@ismail2ov Great, let's go with that for now and we'll re-visit BodyFilters in general and whether we should skip or augment them with exception handling in general (not just the JSON ones). |
In Spring Framework, for GET requests the RequestBody is an empty string and throws an error when we want to apply the filter.
Types of changes
Checklist: