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

streaming endpoint URL not at the main domain #176

Closed
mehrvarz opened this issue Mar 5, 2023 · 2 comments
Closed

streaming endpoint URL not at the main domain #176

mehrvarz opened this issue Mar 5, 2023 · 2 comments

Comments

@mehrvarz
Copy link

mehrvarz commented Mar 5, 2023

The streaming endpoint URL may not be located at the main domain. For instance mastodon.social has it's streaming endpoint at streaming.mastodon.social.

streaming.go currently expects the endpoint to be at the main domain. The actual URL should probably be fetched in StreamingUser() and handed over to streaming() in full. Both methods would need to be touched. Do you want me to apply the change?

@mehrvarz
Copy link
Author

mehrvarz commented Mar 6, 2023

This solves the problem for me.

diff --git a/streaming.go b/streaming.go
index 2439d67..05c7d6a 100644
--- a/streaming.go
+++ b/streaming.go
@@ -102,6 +102,22 @@ func (c *Client) streaming(ctx context.Context, p string, params url.Values) (ch
        if err != nil {
                return nil, err
        }
+
+       instance,err := c.GetInstance(ctx)
+       if err!=nil {
+               // no instance: ignore
+       } else {
+               streaming_api := instance.URLs["streaming_api"]
+               if streaming_api!="" {
+                       u2, err := url.Parse(streaming_api)
+                       if err != nil {
+                               // streaming_api parse error: ignore
+                       } else if u2.Host!="" {
+                               u.Host = u2.Host
+                       }
+               }
+       }
+
        u.Path = path.Join(u.Path, "/api/v1/streaming", p)
        u.RawQuery = params.Encode()

@mehrvarz
Copy link
Author

mehrvarz commented Mar 8, 2023

Update: mastodon/mastodon#23383 (comment)

@mehrvarz mehrvarz closed this as completed Mar 8, 2023
alexbakker added a commit to alexbakker/go-mastodon that referenced this issue Mar 11, 2023
Apparently we shouldn't make assumptions about the streaming endpoint.
See: mastodon/mastodon#23383 (comment)

Also related: mattn#176
mattn pushed a commit that referenced this issue Oct 24, 2024
Apparently we shouldn't make assumptions about the streaming endpoint.
See: mastodon/mastodon#23383 (comment)

Also related: #176
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

1 participant