Obtain streaming url from Mastodon instance info
Apparently we shouldn't make assumptions about the streaming endpoint. See: https://github.com/mastodon/mastodon/issues/23383#issuecomment-1455054265 Also related: #176pull/178/head
parent
9faaa4f0dc
commit
92af8a1078
13
streaming.go
13
streaming.go
|
@ -118,11 +118,11 @@ func (c *Client) streaming(ctx context.Context, p string, params url.Values) (ch
|
|||
u.Path = path.Join(u.Path, "/api/v1/streaming", p)
|
||||
u.RawQuery = params.Encode()
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req = req.WithContext(ctx)
|
||||
req.URL = u
|
||||
|
||||
if c.Config.AccessToken != "" {
|
||||
req.Header.Set("Authorization", "Bearer "+c.Config.AccessToken)
|
||||
|
@ -138,6 +138,15 @@ func (c *Client) streaming(ctx context.Context, p string, params url.Values) (ch
|
|||
default:
|
||||
}
|
||||
|
||||
if i, err := c.GetInstance(ctx); err == nil {
|
||||
if su, ok := i.URLs["streaming_api"]; ok {
|
||||
if u2, err := url.Parse(su); err == nil && u2.Host != "" {
|
||||
u.Host = u2.Host
|
||||
req.Host = u.Host
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c.doStreaming(req, q)
|
||||
}
|
||||
}()
|
||||
|
|
Loading…
Reference in New Issue