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

stream data? #105

Open
paymok opened this issue Apr 26, 2022 · 1 comment
Open

stream data? #105

paymok opened this issue Apr 26, 2022 · 1 comment

Comments

@paymok
Copy link

paymok commented Apr 26, 2022

I used to use Nahi/httpClient but recently got hit by a SSL problem, hence i decided to switch to manticore.
great library It solve my problems on SSL connection, but one thing i needed to do is able to stream data.
In my use case i need to process a huge multipart content(> 600MB ~1GB), downloading it all to memory is not a good idea hence i used to use "get_content" in nahi/httpClient , which can process the content by chunk.

I tried to do the same in manticore but looks like i can only use the response when entire response loaded
Want to know is there any function allow to handle stream data? or am i missing something?

@cheald
Copy link
Owner

cheald commented Apr 26, 2022

Manticore::Response#body accepts a block. If the block is given, then the response stream will be read in 4kb chunks and yielded to the block.

client.get("http://example.com/resource").on_success do |response|
  response.body do |chunk|
    # Do something with chunk, which is a parsed portion of the returned body
  end
end

The actual read is performed by EntityConverter.streamEntity.

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

No branches or pull requests

2 participants