public < T > Response < T > toResponse ( ResponseHandler < T > handler ) { ResponseInfo responseInfo = new ResponseInfo ( this . url , this . statusCode , this . headers , body ( ) ) ; try { T result = handler . handle ( responseInfo ) ; return new Response <> ( this . url , this . statusCode , this . cookies , this . headers , result ) ; } catch ( IOException e ) { throw new RequestsException ( e ) ; } finally { close ( ) ; } }
Handle response body with handler return a new response with content as handler result . The response is closed whether this call succeed or failed with exception .