I’m attempting to receive SSE from a Mastodon instance, following the API described in the official docs.
Firstly, I can’t get HTTP.open
to work. Attempting:
HTTP.open("get", "https://aus.social/api/v1/streaming/public?access_token=$token"; status_exception=false) do io
while !eof(io)
println(String(readavailable(io)))
end
end
results in a 400 Bad Request
from nginx. However, this:
io = IOBuffer()
r = @async HTTP.get("https://aus.social/api/v1/streaming/public?access_token=$token"; response_stream=io, status_exception=false)
println(r)
works fine and I can then read from IO
to access the SSE. What am I doing wrong in the first part? (I’ve tried various combinations of startwrite
, closewrite
, and startread
on IO
without success)
Secondly, in the second example, the task r
never finishes (istaskdone(r)
is always false). Is this a problem if I keep starting tasks like this? Is there some way to end them when I’m done? Or is there a better way in general?