Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OkHttpClient close connection

I'd like to use OkHttpClient to load a url, and if the website at the given url responds with a pdf content type I will go ahead and download the PDF, otherwise I want to ignore the response.

My question is, do I need to do anything special to close the request/response or do I need to do anything to indicate that i won't be using the response if I choose to not read the response bytestream? If not, when does OkHttpClient close the connection?

like image 329
Wise Shepherd Avatar asked Mar 15 '15 00:03

Wise Shepherd


1 Answers

Calling response.body().close() will release all resources held by the response. The connection pool will keep the connection open, but that'll get closed automatically after a timeout if it goes unused.

like image 139
Jesse Wilson Avatar answered Sep 19 '22 15:09

Jesse Wilson