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

Response streaming? #225

Open
CyberShadow opened this issue Feb 27, 2024 · 5 comments
Open

Response streaming? #225

CyberShadow opened this issue Feb 27, 2024 · 5 comments

Comments

@CyberShadow
Copy link

Hi,

Is it possible to receive response data incrementally? E.g. for Content-Type: text/event-stream responses?

I kinda managed to get it to work with url with an after-change-functions hook, but that seems hacky and there doesn't seem to be a clean way to interrupt an in-progress request.

Thanks!

@dickmao
Copy link
Collaborator

dickmao commented Feb 27, 2024

I kinda managed to get it to work with url with an after-change-functions hook,

You mean like this?

(let ((b (url-retrieve "https://httpbin.org/range/1024?duration=8&chunk_size=64"
                       (lambda (&rest _args) (kill-buffer)))))
  (push (lambda (beg end _len)
	  (message "Got %s" (buffer-substring beg end)))
	(buffer-local-value 'after-change-functions b)))

I wouldn't use this library anymore. It's slow and more trouble than it's worth. Granted the built-in url library is written in precisely the wrong way, but I still prefer it to clumsily spawning a curl subprocess.

@CyberShadow
Copy link
Author

You mean like this?

Yes, that's what I'm doing. Aside from the problem of how to disconnect, the above code is not quite correct when something like "Content-Encoding: chunked" is used. But if you stick the hook in a 0-second timer so that it runs after url does its postprocessing, then it seems to work fine.

I wouldn't use this library anymore.

Sorry, do you mean url or request?

Either way, what would you recommend?

@dickmao
Copy link
Collaborator

dickmao commented Feb 27, 2024

I wouldn't use request. It sucks, and while Content-Encoding: chunked, whatever that means, doesn't work out of the box with url, I wouldn't attempt to get it to work with request. I also gag slightly when I hear about 0-second timers. Sorry bruh. Will accept crypto if you want me to do it right nice. Problem statement must be terse and limited to 500 words including code snippets.

@CyberShadow
Copy link
Author

Err, thanks, writing code is not the problem. It's all going up on GitHub in the end anyway. Was just wondering if there's a more established library I should be using instead. Cheers.

@dickmao
Copy link
Collaborator

dickmao commented Feb 27, 2024

I believe some nimrod is floating his own http library as an alternative to this one which he denigrates every chance he gets. Google around.

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