spring-cloud / spring-cloud/spring-cloud-gateway
spring-cloud-starter-gateway-server-webflux 4.3.0 cann't relay web socket header “Sec-WebSocket-Extensions” , cause response message does not compression
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.9k
- Forks
- 3.5k
- Avg merge
- 20h 57m
- Merged PRs (30d)
- 8
Description
Describe the bug
use sockjs connect spring message broker server。
Use wireshark to capture packets. When using sockjs to connect to the websocket server through the gateway, the response message is not compressed. When using sockjs to directly connect to the websocket server, the response message is compressed.
Sample
through the gateway message example request data
request :
GET ws://127.0.0.1:10003/app-main/websocket/112/oqhvfdf5/websocket HTTP/1.1
Host: 127.0.0.1:10003
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Upgrade: websocket
Origin: http://127.0.0.1:10003
Sec-WebSocket-Version: 13
Accept-Encoding: gzip, deflate, br, zstd
Accept-Language: zh-CN,zh;q=0.9
Cookie: _ga=GA1.1.519644543.1748339907; _ga_0C4M1PWYZ7=GS2.1.s1748339907$o1$g1$t1748340232$j0$l0$h0; _ga_K2SPJK2C73=GS2.1.s1748339907$o1$g1$t1748340232$j60$l0$h0; _ga_T11SF3WXX2=GS2.1.s1748339907$o1$g1$t1748340232$j60$l0$h0; apt.uid=AP-YFGMCGUNNIFB-2-1748576499518-11838672.0.2.a2e3917a-4f22-4c24-8671-436b74b600a2; FRAMEWORK-SESSION=MTY5OWJmZTItMzk1Zi00MmFkLThiNjItNWZjMmM4N2RhZDdk; JSESSIONID=29760225F533A9A9B9416DE8A8D81462
Sec-WebSocket-Key: piuh643B6mzCZhQrG7bniQ==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
response:
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 0
Referrer-Policy: no-referrer
upgrade: websocket
connection: upgrade
sec-websocket-accept: 9TZIb22MKG6Go3j9Hcc+xyAVgfs=
directly connect to the websocket server request response header
request:
GET ws://127.0.0.1:7101/app-main/websocket/174/1qrq0hj1/websocket HTTP/1.1
Host: 127.0.0.1:7101
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Upgrade: websocket
Origin: http://127.0.0.1:10003
Sec-WebSocket-Version: 13
Accept-Encoding: gzip, deflate, br, zstd
Accept-Language: zh-CN,zh;q=0.9
Sec-WebSocket-Key: 5OiR1HIaRH2d9fmojEnqOg==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
response:
HTTP/1.1 101
Access-Control-Allow-Origin: http://127.0.0.1:10003
Access-Control-Allow-Headers: X-Cookie,x-requested-with,authorization,Content-Type,Authorization,credential,X-XSRF-TOKEN,X-Route,X-CSRF
Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: *
Access-Control-Max-Age: 3600
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Upgrade: websocket
Connection: upgrade
Sec-WebSocket-Accept: p76T0EfnD7uuk+Sq1+9xR/7jhbE=
Sec-WebSocket-Extensions: permessage-deflate;client_max_window_bits=15
X-Content-Type-Options: nosniff
X-XSS-Protection: 0
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: SAMEORIGIN
Date: Thu, 28 Aug 2025 08:33:26 GMT
Analysis of wireshark packet capture data gateway did not pass the request header “Sec-WebSocket-Extensions” to the websocket server,cause reponse data do not compression,and also response header dose not have the header “Sec-WebSocket-Extensions: permessage-deflate;client_max_window_bits=15”
How can I make the websocket messages passing through the gateway compressed?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with spring-cloud-starter-gateway-server-webflux WebSocket proxy handling and reproduce the SockJS connection through the gateway. Compare the forwarded request and returned response headers with the direct connection; done when Sec-WebSocket-Extensions is preserved and permessage-deflate is negotiated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring, spring-boot
- Domain
- api, backend, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100