forwardStream relays the upstream SSE response to the client, flushing per read so events arrive in real time. Response/output PII redaction is out of scope for now, so the stream is forwarded unmodified.
(c echo.Context, body io.Reader)
| 64 | // redaction is out of scope for now, so the stream is forwarded |
| 65 | // unmodified. |
| 66 | func forwardStream(c echo.Context, body io.Reader) error { |
| 67 | c.Response().Header().Set("Content-Type", "text/event-stream") |
| 68 | c.Response().Header().Set("Cache-Control", "no-cache") |
| 69 | c.Response().Header().Set("Connection", "keep-alive") |
| 70 | c.Response().WriteHeader(http.StatusOK) |
| 71 | |
| 72 | buf := make([]byte, 32*1024) |
| 73 | for { |
| 74 | n, rErr := body.Read(buf) |
| 75 | if n > 0 { |
| 76 | if _, wErr := c.Response().Writer.Write(buf[:n]); wErr != nil { |
| 77 | return nil |
| 78 | } |
| 79 | c.Response().Flush() |
| 80 | } |
| 81 | if rErr != nil { |
| 82 | if rErr != io.EOF { |
| 83 | xlog.Debug("cloudproxy: stream read error", "error", rErr) |
| 84 | } |
| 85 | return nil |
| 86 | } |
| 87 | } |
| 88 | } |
no test coverage detected