Closed buger closed 1 month ago
API Changes
--- prev.txt 2024-07-11 09:41:37.815476924 +0000
+++ current.txt 2024-07-11 09:41:35.055495578 +0000
@@ -7274,9 +7274,6 @@
InstrumentationMW will set basic instrumentation events, variables and
timers on API jobs
-func IsGrpcStreaming(r *http.Request) bool
- IsGrpcStreaming determines wether a request represents a grpc streaming req
-
func JSONToFormValues(r *http.Request) error
JSONToFormValues if r has header Content-Type set to application/json this
will decode request body as json to map[string]string and adds the key/value
@@ -9664,7 +9661,10 @@
func (p *ReverseProxy) HandleResponse(rw http.ResponseWriter, res *http.Response, ses *user.SessionState) error
-func (p *ReverseProxy) IsUpgrade(req *http.Request) (bool, string)
+func (p *ReverseProxy) IsUpgrade(req *http.Request) (string, bool)
+ IsUpgrade will return the upgrade header value and true if present for the
+ request. It requires EnableWebSockets to be enabled in the gateway HTTP
+ server config.
func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) ProxyResponse
β±οΈ Estimated effort to review: 4 π΅π΅π΅π΅βͺ |
π§ͺ PR contains tests |
π No security concerns identified |
β‘ Key issues to review **Possible Bug:** The refactoring in `gateway/reverse_proxy.go` changes the handling of streaming requests and responses. Ensure that the new checks (`httputil.IsStreamingRequest(req) || httputil.IsStreamingResponse(res)`) correctly handle all cases previously covered by specific gRPC and WebSocket checks. **Performance Concern:** The new streaming utility functions in `internal/httputil/streaming.go` are called multiple times within the same request cycle. This could introduce unnecessary overhead due to repeated header checks. Consider optimizing by storing results in the request context. **Regression Risk:** The changes to how upgrades and streaming are detected and handled could potentially introduce regressions in edge cases not covered by tests, especially in environments with mixed types of streaming and non-streaming traffic. |
Category | Suggestion | Score |
Possible issue |
Ensure the return values from
___
**The | 10 |
Best practice |
Replace
___
**Replace the | 8 |
Enhancement |
Enhance the
___
**Refactor the | 7 |
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
95.0% Coverage on New Code
0.0% Duplication on New Code
User description
TT-12318 SSE streaming is broken (#6391)
User description
This PR mends the evaluation if the cache should be used, considering:
Previously the checks would handle only the request side to set a caching flag to true; the change sets the flag to true absolutely, and then evaluates the request and response disabling the cache before copying the request into a buffer can occur.
The underlying cause/issue of the regression was a skipped flaky test for SSE. The test case has now been restored to health.
Fixes: https://tyktech.atlassian.net/browse/TT-12318 https://tyktech.atlassian.net/browse/TT-5250
Closes: #6322
PR Type
Enhancement, Tests, Configuration changes
Description
Changes walkthrough π
handler_success.go
Replace gRPC streaming check with generic streaming request check
gateway/handler_success.go - Replaced `IsGrpcStreaming` with `httputil.IsStreamingRequest`.
reverse_proxy.go
Refactor reverse proxy to handle streaming requests and responses
gateway/reverse_proxy.go
IsGrpcStreaming
withhttputil.IsStreamingRequest
.ServeHTTP
method by removing conditional streaming check.IsUpgrade
method to return upgrade type and boolean.streaming.go
Add utility functions for streaming and upgrade checks
internal/httputil/streaming.go
reverse_proxy_test.go
Refactor and stabilize SSE test
gateway/reverse_proxy_test.go
Makefile
Simplify linting commands in Makefile
Makefile - Simplified linting commands by using `task lint`.
docker-compose.yml
Modularize service definitions in Docker Compose
docker-compose.yml
docker-compose.yml
Include HTTPBin service in Docker Compose
docker/services/docker-compose.yml - Included HTTPBin service definition.
httpbin.yml
Add HTTPBin service definition
docker/services/httpbin.yml - Added HTTPBin service definition for testing.
Co-authored-by: Tit Petric tit@tyk.io
PR Type
Enhancement, Tests, Configuration changes
Description
Changes walkthrough π
handler_success.go
Replace gRPC streaming check with generic streaming request check
gateway/handler_success.go
request check.
reverse_proxy.go
Refactor reverse proxy logic for streaming requests and responses
gateway/reverse_proxy.go
responses.
streaming.go
Add utility functions for streaming and upgrade checks
internal/httputil/streaming.go - Added utility functions for streaming and upgrade checks.
reverse_proxy_test.go
Refactor and stabilize SSE test
gateway/reverse_proxy_test.go
Makefile
Simplify linting commands
Makefile - Simplified linting commands.
docker-compose.yml
Modularize service definitions in Docker Compose
docker-compose.yml
HTTPBin services.
docker-compose.yml
Include external Redis and HTTPBin services
docker/services/docker-compose.yml - Included external Redis and HTTPBin services.
httpbin.yml
Add HTTPBin service definition
docker/services/httpbin.yml - Added HTTPBin service definition.