Skip to content
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

Reading HTTP Response When Request Isn't Fully Sent #4425

Closed
dzelemba opened this issue Nov 30, 2018 · 9 comments
Closed

Reading HTTP Response When Request Isn't Fully Sent #4425

dzelemba opened this issue Nov 30, 2018 · 9 comments
Labels
enhancement Feature not a bug
Milestone

Comments

@dzelemba
Copy link

If I send a large POST request using OkHttp, but the server responds quickly with an error (e.g. permission denied) I get a

java.net.SocketException: Broken pipe (Write failed)( status = 272 )

exception.

Command line tools like curl seem to handle this case just fine and are able to return the HTTP Response instead of aborting because the write failed. Can okhttp do the same?

Note: also asked here https://stackoverflow.com/questions/53451467/reading-http-response-when-request-isnt-fully-sent.

@swankjesse swankjesse added the enhancement Feature not a bug label Dec 28, 2018
@swankjesse swankjesse added this to the Backlog milestone Dec 28, 2018
@swankjesse
Copy link
Collaborator

Tough one. I’m not sure.

@bstsnail
Copy link

I have the same problem, still don't know how to get the response

@yschimke
Copy link
Collaborator

Won't fix.

@drtrang
Copy link

drtrang commented Jun 29, 2020

Won't fix.

Why? It confuses me.

@dzelemba
Copy link
Author

For anyone struggling with this issue, we did end up getting it to work using Jetty and HTTP 2.0: https://github.com/GoogleCloudPlatform/healthcare-dicom-dicomweb-adapter/blob/master/dicom_util/src/main/java/com/google/cloud/healthcare/DicomWebClientJetty.java#L65

@swankjesse
Copy link
Collaborator

Related: #6121

@jan-berge-ommedal
Copy link

jan-berge-ommedal commented Feb 25, 2021

@swankjesse I have been testing the latest alpha-release and was happy to see early server responses handled much better than before! The fix works great when the server decides to end the exchange early.

However, i have another use-case where the request body source stream might fail client-side during transmission. In this case, an exception is thrown because of:

https://github.com/square/okhttp/blob/master/okhttp/src/main/kotlin/okhttp3/internal/http/CallServerInterceptor.kt#L86

if (!exchange.hasFailure) {
        throw e // Don't attempt to read the response; we failed to send the request.
}

even if we actually did manage to partially send the request.

It would be nice to still be able to get the server response code (typically 4xx/5xx) + headers/trailers in this case. I started sketching on a way to fix this: master...jan-berge-ommedal:partial_requests

Could something like this be fitted into okhttp?

@yschimke
Copy link
Collaborator

yschimke commented Feb 26, 2021

@jan-berge-ommedal rather than comment on this issue, why not put up a proper PR with the current diff to work through.

@jan-berge-ommedal
Copy link

PR up @yschimke, sorry for the late response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature not a bug
Projects
None yet
Development

No branches or pull requests

6 participants