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

Close OkHttp response body #945

Closed
wants to merge 1 commit into from
Closed

Conversation

drei01
Copy link

@drei01 drei01 commented Dec 10, 2019

Response body must be closed, see square/okhttp#2311

@k3muri84
Copy link

k3muri84 commented Jan 8, 2020

how is this change closing the body? can u explain?

try (ResponseBody body = okHttpResponse.body()) {
return new Response(okHttpResponse.code(), okHttpResponse.message(), headersMap,
body == null ? null : body.byteStream());
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't there be a finally? i don't get how this closes the body.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok cool

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @drei01 , ResponseBody shouldn't be closed here in such way.
it is passed to the com.github.scribejava.core.model.Response.
and is used by it to read body stream later.
Developers should close com.github.scribejava.core.model.Response. And it will close the stream.
Response implements Closeable and have method

    @Override
    public void close() throws IOException {
        if (stream != null) {
            stream.close();
        }
    }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kullfar thanks for the clarification. I'll close this PR.

@drei01 drei01 closed this Mar 31, 2020
@kullfar
Copy link
Member

kullfar commented Mar 31, 2020

But.... You're right, that only byteStream will be closed, not the ResponseBody. I will make some changes soon.

@kullfar
Copy link
Member

kullfar commented May 5, 2020

that's it
b2458a8

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

Successfully merging this pull request may close these issues.

3 participants