-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Calling response.body.string() on a MockWebServer response throws a SocketTimeoutException #8395
Comments
Interceptors must not consume the response body. This is forbidden because it prevents the original caller from consuming the streamed response body. You can work-around this by using Use whatever value you want other than 5 for the number of bytes to peek. You can use |
Thank you for the response. However, using |
I wrote a simple test but can't reproduce your issue (no SocketTimeoutException).
|
I now finally found out what causes the SocketTimeoutException. In my example, I add the headers to the MockResponse. So even your simple test crashes with the SocketTimeoutException right at the MockResponse().setResponseCode(200).setBody("{ body content }").setHeaders(
Headers.headersOf(
"Set-Cookie",
"sessionId=someId; path=/; samesite=None;"
)
) The stacktrace is:
If I remove the |
I think the issue raises because the
|
Just had the same issue - fixed by either:
|
I have an Android Instrumentation test where I simply call my API and return a MockResponse, something like:
I use a custom dispatcher to return the Response:
The mockWebServer is set up as follows:
Then I call the API using RxJava
Now, I have an interceptor which causes the issue:
Why is the SocketTimeoutException thrown? With the real server, the interceptor works and there is no issue calling the response.body.string() function. When I remove this interceptor, the test succeeds and the body is also correctly parsed with Jackson. Is there a bug in the MockWebServer implementation?
The text was updated successfully, but these errors were encountered: