-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Branch/Environment/Version
- Branch/Version: https://github.com/TykTechnologies/tyk/tree/v5.7.2 (but code causing bug is identical in 5.9.0rc6
- Environment: On-prem
Describe the bug
Tyk.io is not able to detect SSE responses if the Content-Type
response header contains charset indications:
Content-Type: text/event-stream; charset=utf-8
. E.g. FastAPI use this charset indication per default for SSE responses.
The code responsible to detect SSE responses in tyk is:
tyk/internal/httputil/streaming.go
Line 20 in ff9eb63
func IsSseStreamingResponse(r *http.Response) bool { |
// IsSseStreamingResponse returns true if the response designates SSE streaming.
func IsSseStreamingResponse(r *http.Response) bool {
return r.Header.Get(headerContentType) == "text/event-stream"
}
Replacing the exact string match with something like
// IsSseStreamingResponse returns true if the response designates SSE streaming.
func IsSseStreamingResponse(r *http.Response) bool {
return strings.HasPrefix(r.Header.Get(headerContentType), "text/event-stream")
}
shuld fix the issue.
Reproduction steps
Steps to reproduce the behavior:
I created this GitHub repo with an example server to reproduce the behaviour: FastAPI SSE
docker run yanickbs/fastapi-sse:latest
- Publish an API with the following configuration:
- Set an appropriate listen path, e.g.
"listen_path": "/sse"
- Strip the listen path from the request URL, e.g.
"strip_listen_path": true
- Set the target URL to the server, e.g.
"target_url": "http://host.docker.internal:8000/sse"
- Configure the API endpoints
GET /sse
andGET /sse-fixed-header
- Click Save, and wait for the API to be published.
- Set an appropriate listen path, e.g.
- Test the protected SSE service via
curl -vvv http://localhost:8000/sse/sse
andcurl -vvv http://localhost:8000/sse/sse-fixed-header
and check the response headers.
Actual behavior
The response arrives at the CURL client in one message after the SSE is finished.
You get this behavior using this CURL: curl -vvv http://localhost:8000/sse/sse
Expected behavior
The response arrives event by event to the CURL client.
You get this response with this CURL:
curl -vvv http://localhost:8000/sse/sse-fixed-header
Configuration (tyk config file):
Follow the official documentation to configure the API Gateway to use the server.