(ctx context.Context, id string)
| 223 | } |
| 224 | |
| 225 | func (c *eventClient) OpenStream(ctx context.Context, id string) (io.ReadCloser, error) { |
| 226 | if !SupportedHost(c.host) { |
| 227 | return nil, ErrUnsupportedHost |
| 228 | } |
| 229 | |
| 230 | path, err := safeurl.JoinPath("event-subscriptions", id, "events") |
| 231 | if err != nil { |
| 232 | return nil, err |
| 233 | } |
| 234 | |
| 235 | resp, err := c.api.RequestWithContext(ctx, c.host, http.MethodGet, path.String(), nil, api.WithHeader("Accept", "text/event-stream")) |
| 236 | if err != nil { |
| 237 | if httpErr, ok := errors.AsType[api.HTTPError](err); ok { |
| 238 | switch { |
| 239 | case httpErr.StatusCode == http.StatusNotFound: |
| 240 | return nil, fmt.Errorf("%w: %w", ErrSubscriptionNotFound, err) |
| 241 | case httpErr.StatusCode == http.StatusForbidden: |
| 242 | return nil, forbiddenError(httpErr, err) |
| 243 | } |
| 244 | } |
| 245 | return nil, err |
| 246 | } |
| 247 | mediaType, _, _ := mime.ParseMediaType(resp.Header.Get("Content-Type")) |
| 248 | if mediaType != "text/event-stream" { |
| 249 | resp.Body.Close() |
| 250 | return nil, fmt.Errorf("unexpected event stream content type %q", resp.Header.Get("Content-Type")) |
| 251 | } |
| 252 | return resp.Body, nil |
| 253 | } |
| 254 | |
| 255 | // forbiddenError tells a 403 response for an account without preview access apart from other denials. It keeps the |
| 256 | // HTTP error wrapped, so callers treat it as final rather than retrying it. |
nothing calls this directly
no test coverage detected