bogdanfinn / tls-client

net/http.Client like HTTP Client with options to select specific client TLS Fingerprints to use for requests.
BSD 4-Clause "Original" or "Old" License
860 stars 164 forks source link

fixed readAllBodyWithStreamToFile function #123

Closed tigersoft6084 closed 4 months ago

tigersoft6084 commented 4 months ago

I was using tls-client in conjunction with Node.js and encountered an issue while handling large file downloads. Specifically, I tried to set streamOutputPath to save the response body directly to a file. However, tls-client attempted to send the entire response as a JSON object, causing it to hang. Additionally, when using the withDebug option, it printed the entire response body, which was very inefficient.

To address these issues, I made the following updates to the code:

  1. Empty Response Body with streamOutputPath: When streamOutputPath is set, the code now returns an empty response body instead of attempting to convert the entire response to JSON.
  2. EOF Error Handling: Fixed a bug that prevented the last body snippet from being processed correctly due to an EOF error.

These changes ensure that large file downloads are handled efficiently and that the response body is managed appropriately when using streamOutputPath.