Open sizmestiev opened 3 years ago
Thinking aloud here. As an empty string is not a valid JSON, JacksonResponseReader
's behavior is probably correct in this case. In the case of a text/plain
response it would make sense to return an empty String when the response body is empty. However, String cannot implement HttpResponseAware
. So I'm not sure how to proceed.
What is the declared content type of the response?
Oh actually JacksonResponseReader
's behavior is not correct with the empty string -- it should probably throw an exception (invalid json).
Anyhow, this probably doesn't help much either.
What is the declared content type of the response?
I see now that no content type is declared in the response.
Is it possible to add ability to specify a custom ResponseReader
in addition to Jackson
and text/plain
?
Is it possible to add ability to specify a custom
ResponseReader
in addition toJackson
andtext/plain
?
Currently, no. I see you've delved into rescu source code -- if you create a pull request implementing this ability, I'll be happy to review.
A workaround/hack might exist for your issue though. Exceptions can implement HttpResponseAware, so if you manage to have an exception thrown when processing the response you might be able to get the headers. Unfortunately I don't see an easy way to do this as this is generally only triggered when the response body cannot be parsed or when the http response code is not 2xx. It would help if the code you linked were change to not return null on empty response and try to parse it as json (empty string is illegal json), but I'm afraid that might break many existing implementations that rely on the current behavior.
if you create a pull request implementing this ability, I'll be happy to review.
Thank you.
I don't have enough time now to implement the ability carefully, but this functionality is extremely important to me.
I'll do my best when I'm ready.
Hello Matija.
I have interaction with an exchange which sends authentication information in the headers of empty response.
Both JSON and plain text readers are unable to create
HttpResponseAware
object for empty responses - they just returnnull
: https://github.com/mmazi/rescu/blob/55a60966f1aa1ce81a83a8ba50d06aabe42c84d1/src/main/java/si/mazi/rescu/ResponseReader.java#L62I wonder - is there a way to receive any object for such empty responses to handle the response headers?
Sample response: