NewWatchEventsStreamRequest builds an authenticated GET request for GET /api/v1/events/stream (TASK-2533), used by `pad watch --stream --for-session`. Deliberately returns the request rather than doing the round trip itself: an SSE connection is meant to stay open for a whole session, and both c.htt
(ctx context.Context, lastEventID string, ident StreamSessionIdentity)
| 399 | // http.Client. lastEventID, when non-empty, is sent as Last-Event-ID for |
| 400 | // resume; ident, when non-zero, announces the session (S2). |
| 401 | func (c *Client) NewWatchEventsStreamRequest(ctx context.Context, lastEventID string, ident StreamSessionIdentity) (*http.Request, error) { |
| 402 | req, err := c.newRequest("GET", "/events/stream", nil) |
| 403 | if err != nil { |
| 404 | return nil, err |
| 405 | } |
| 406 | req = req.WithContext(ctx) |
| 407 | req.Header.Set("Accept", "text/event-stream") |
| 408 | req.Header.Set("Cache-Control", "no-cache") |
| 409 | if lastEventID != "" { |
| 410 | req.Header.Set("Last-Event-ID", lastEventID) |
| 411 | } |
| 412 | if label := headerSafeLabel(ident.Label); label != "" { |
| 413 | req.Header.Set("X-Pad-Session-Label", label) |
| 414 | } |
| 415 | if ident.PID > 0 { |
| 416 | req.Header.Set("X-Pad-Session-Pid", strconv.Itoa(ident.PID)) |
| 417 | } |
| 418 | return req, nil |
| 419 | } |
| 420 | |
| 421 | // maxHeaderLabelLen bounds the label the client is willing to put on |
| 422 | // the wire, in runes. It is deliberately looser than the server's own |