![]() | 1 guanhui07 226 天前 抓请求头 和 返回头吧 |
2 xxkuboy 226 天前 nginx 没配置吧,好像有个什么缓存的要关了 |
3 ex1gtnim7d 226 天前 被网关缓存了,每一层网关都要检查 |
![]() | 4 xuelang 226 天前 哈哈,上面 nginx 代理也有 sse 相关的配置的 |
![]() | 5 magicZ 226 天前 public void demo( HttpServletResponse httpServletResponse) throws IOException { httpServletResponse.setContentType("text/event-stream"); httpServletResponse.setCharacterEncoding("UTF-8"); httpServletResponse.setHeader("Cache-Control", "no-cache"); ServletOutputStream outputStream = httpServletResponse.getOutputStream(); while{ outputStream.write(("data: " + 字符串 + "\n\n").getBytes()); } outputStream.write(("data: done\n\n").getBytes()); outputStream.flush(); } 查查 sse 的教程 https://www.ruanyifeng.com/blog/2017/05/server-sent_events.html |
![]() | 6 lavvrence 226 天前 大概率 HTTP 版本低于 HTTP/1.1 。 |
7 rainfy OP @guanhui07 Response Headers: HTTP/1.1 200 OK Transfer-Encoding: chunked Access-Control-Allow-Credentials: true Access-Control-Allow-Origin: null Access-Control-Expose-Headers: permission, username, eagleeye-traceid Connection: keep-alive Content-Type: text/event-stream;charset= Date: Wed, 26 Feb 2025 02:00:08 GMT Keep-Alive: timeout=4 Proxy-Connection: keep-alive Server: f6car Set-Cookie: romaSESSIOnID=de1f56ef-5301-412a-8537-abe613dd1dc1; Path=/roma; HttpOnly Vary: Origin X-Application-Context: xx:test:8888 Request Headers: GET /xx/sse/connect HTTP/1.1 Accept: text/event-stream Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9 Cache-Control: no-cache DNT: 1 Host: report-pre.f6car.com Origin: null Proxy-Connection: keep-alive User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 |
8 rainfy OP @jaylee4869 GET /xx/sse/connect HTTP/1.1 |
![]() | 9 CHTuring 226 天前 Ngnix ``` proxy_ssl_verify off; proxy_ssl_session_reuse off; proxy_buffering off; # 禁用缓存 ``` |
![]() | 11 yevXxHmg 226 天前 大概率 nginx 的配置,网络链路上经过的中间件都排查下看看 |
![]() | 12 KingFong PRO ![]() nginx 的 proxy_buffering 配置,或者你响应头带一个 X-Accel-Buffering: no 也可以,详见 https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering |
![]() | 13 weenhall5 226 天前 proxy_http_version 1.1; # 设置 SSE 连接的超时时间,不设置默认是 2.5 分钟 proxy_read_timeout 86400s; # 关闭缓冲 proxy_buffering off; # 关闭代理缓存 proxy_cache off; |
14 salmon5 226 天前 sse 这一个 proxy_buffering off;就好了,其它默认 |
17 foolyf 226 天前 后端返回的流式输出效果不一定是平滑的,需要前端在做一层过滤来输出,这样才能达到平滑输出的效果。 |
18 SoulFlame 226 天前 ![]() 我也做了这个需求,我在后端代码加多了 3 个响应头: Content-Type: text/event-stream Cache-Control: no-cache X-Accel-Buffering: no |
![]() | 20 lambdaq ![]() X-Accel-Buffering: no 就行。别去瞎改 nginx 配置。 |
![]() | 21 japeth 225 天前 我这边使用的 go 语言,gin 封装的脚手架,要把 gzip 要关掉 。 |