-
Notifications
You must be signed in to change notification settings - Fork 180
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
Differences between open("GET", url) do io
and request("GET", url; response_stream=io)
?
#793
Comments
Note that
so with Note also that |
Oh, well these two issues could very well explain why it didn't work for me. |
Now I have a different but I think connected problem. Again I had an implementation using using HTTP
using JSON
header = Dict("Authorization" => "Bearer $(ENV["LICHESS_TOKEN"])")
eventUrl = "https://lichess.org/api/stream/event" works as expected: HTTP.open("GET", eventUrl, header) do http
while !eof(http)
s = String(readavailable(http))
println(s)
(length(s) < 5 || isnothing(findfirst('{', s))) && continue
state = JSON.parse(s)
if state["type"] == "challenge"
challengeId = state["challenge"]["id"]
declineUrl = "https://lichess.org/api/challenge/$challengeId/decline"
HTTP.request("POST", declineUrl, header)
end
end
end Output with open
does not work, hangs and doesn't decline: buf = Base.BufferStream()
@async while !eof(buf)
s = String(readavailable(buf))
println(s)
(length(s) < 5 || isnothing(findfirst('{', s))) && continue
state = JSON.parse(s)
if state["type"] == "challenge"
challengeId = state["challenge"]["id"]
declineUrl = "https://lichess.org/api/challenge/$challengeId/decline"
HTTP.request("POST", declineUrl, header)
end
end
HTTP.request("GET", eventUrl, header, response_stream = buf) Output when using StreamBuffer
|
@dave7895, I believe I'm seeing the same behavior for both these examples when running Julia 1.8 and HTTP#master. Please let me know if you're still seeing something off/different/hanging. |
I am using HTTP.jl to stream events as they are coming in. When using
HTTP.open
I can manipulate the data and do what I want but my problem is that errors don't propagate and I can't see them which hurts debugging.So my next approach was to try and use a
BufferStream
or anIOBuffer
and use an asynchronously started while-loop to process the data. But now the problem is that the stream doesn't seem to get the response written to it.According to the debug log create by
verbose=3
there is data coming from the remote, but the loopdoesn't print anything, not even the message that its starting.
Quite possibly it's my approach that is at fault here, not very experienced with both HTTP or buffers in general.
The text was updated successfully, but these errors were encountered: