-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Empty body on HTTP error response #260
Comments
Thanks for the report. Are you able to reproduce this in a MockWebServer
test? (saying no is acceptable :P )
|
Actually, no. I tried the following in BaseApiTest:
And this passes fine, the response gets through without a problem.. Weird! When I had the issue, the remote end was a Jersey-based server. As I mentioned, the tcpdump on localhost showed the actual bytes being sent.. The only difference was that I was using a JacksonDecoder, but I tried that as well and couldn't reproduce the error. Sidenote: even though I specify Full logging level (and forcing the Logger-level on feign.Logger to All), I don't see the http dump as I did in my original code (which uses the Slf4jLogger).. adding a System.out.println line in the log method did show proper output though. |
Tested with both v8.7.1 and master. |
I wonder if something is overriding the URLStreamHandlerFactory like how we do in okhttp: URL.setURLStreamHandlerFactory(new OkUrlFactory(okHttpClient)); This would manifest as a different type of object (like in a different package) for HttpURLConnection. |
This is not a problem in feign - this is how HttpURLConnection works. Currently in the feign.Default client there is a streaming mode enabled. You can see in the sun.net.www.protocol.http.HttpURLConnection following lines of code : So if the streaming is enabled and you have 401 HTTP response code you will get empty errorStream, because there is no initialization. The feign client will try to get the errorStream as a body because there is a check Currently I removed the streaming in the cient. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This feels like a bug to me. We may need more |
This is caused by https://github.com/OpenFeign/feign/blame/master/core/src/main/java/feign/Client.java#L85... Setting |
My recommendation would be to release a minor version with |
这个修复啥时候发布,怎么就把参数定死了。 |
@344310362 english comments are more likely to be understood by most of the people following this project. Google translate isn't very good here as it turns that into:
Perhaps a better translation of "death" would be "null"? |
There issue is marked as help-wanted, indicating that if someone wants to take a look and try to fix this, please do and raise a PR. |
From my side I won't do much, not using it anymore. Not even sure where I used it.. :) |
After looking into this recently, I can see that this behavior is specific to JDK versions prior to 1.8. I'm going to close this issue and recommend that user's test with JDK 1.8. |
Hey guys. I had this problem and set the OkHttp to Openfeign and fixed. In order to know how can use from OkHttp in Openfeign refer to here |
Unfortunately this 'feature' has remained to JDK 11. I just tested |
* Add a property `allowStramingMode` in `Request.Option`. * Optional to disable the streaming mode for `HttpURLConnection`. * The property is default to `true` for compatibility. Fix OpenFeign#260
* Add a property `allowStramingMode` in `Request.Option`. * Optional to disable the streaming mode for `HttpURLConnection`. * The property is default to `true` for compatibility. Fix OpenFeign#260
* Configurable to disable streaming mode for Default client * Add a property `allowStramingMode` in `Request.Option`. * Optional to disable the streaming mode for `HttpURLConnection`. * The property is default to `true` for compatibility. Fix #260 * Fix a merging problem * Make the new option `disableRequestBuffering` to Default client * Move it from `Request.Options` to `Default` client
Did anybody had a workaround to resolve this issue? It is existing I am using JDK 11 and Openfeign 2.2.6. I have tried with other clients other than the default Okhttp and Apache HttpClient and still getting empty response body with 401 error response. |
Same too me , response code = 401 the response body return null, JDK 17, Feign 3.1.4 |
Feign 3? That is 10 releases old. Is like trying to run spring 1 with jdk 17. |
I can confirm that using the okhttp client the problem disappears (https://github.com/OpenFeign/feign/blob/6408e3ef9664ee6594c12d9e3c2cc91fd29119d0/okhttp/src/main/java/feign/okhttp/OkHttpClient.java) To add it to our project we had to: add the pom dependency:
And in the feign config bean, make sure to init your Feign with sth like:
|
I had a problem where the response body would come up empty, when the server responded with 401:
As indicated by content-length header, the body should be 71 bytes, and it is (verified with tcpdump).
The empty body caused a NPE when the ErrorDecoder had nothing to decode and returned null, which SynchronousMethodHandler then tried to throw (line 121).
During previous testing, with 200 OK it worked fine, if I recall correct.
This was with the Default client. Using OkHttpClient instead, the issue disappeared.
The text was updated successfully, but these errors were encountered: