我在使用 sse 推送数据时出现一个现象,使用 iOS、Android 手机和服务器建立 sse 连接,服务器同时通过连接推送 keep_alive 数据,测试过程发现 Android vsConsole 能够即时打印数据(即时接收到数据),但是 iOS 会在连接超时时刻统一打印之前接收到的数据。
因为客户端到服务器请求会经过 Nginx 服务器代理,所以考虑到是 Nginx 缓存的问题,但我在 Nginx 配置里已经将 proxy_buffering 设置为 off,退一步讲如果设置未生效,那为什么 Android 能够即时接收到数据?
基于上面的推理,排除了 Nginx 缓存原因,将排查问题角度转移到了 iOS 和 Android 发出请求的 header 上,因为 iOS 和 Android 底层使用不同的浏览器,有可能请求头存在问题,但是通过对比请求头也没有发现问题。
以上是我的排查问题思路,最后没能解决问题,想问问网上的大佬有别的排查思路吗?
以下是上述排查步骤的信息。
Nginx 配置
location /sse {
set $upstream_namme "域名";
proxy_pass http://upstream_name;
proxy_read_timeout 600s;
proxy_connect_timeout 2000ms;
proxy_buffering off;
proxy_cache off;
proxy_http_version 1.1;
proxy_set_header Connection "";
chunked_transfer_encoding off;
}
iOS Android 请求 header
Android
{
"referer": "",
"cookie": "",
"origin": "",
"x-forwarded-for": "",
"accept": "text/event-stream",
"x-real-ip": "",
"host": "",
"mkoriginhost": "",
"mktunneltype": "http",
"connection": "Upgrade",
"cache-control": "no-cache",
"accept-encoding": "gzip",
"user-agent": "Mozilla/5.0 (Linux; Android 10; YAL-AL00 Build/HUAWEIYAL-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/83.0.4103.106 Mobile Safari/537.36 TitansX/13.0.7 KNB/1.2.0 android/10 mt/com.sankuai.meituan/12.25.213 App/10120/12.25.213 MeituanGroup/12.25.213",
"mkscheme": "https"
}
iOS
{
"referer": "",
"sec-fetch-site": "cross-site",
"origin": "",
"x-titans-user": "",
"host": "",
"mkoriginhost": "",
"connection": "Upgrade",
"cache-control": "no-cache",
"sec-fetch-mode": "cors",
"accept-language": "zh-CN,zh-Hans;q=0.9",
"cookie": "",
"mkunionid": "",
"x-forwarded-for": "",
"pragma": "no-cache",
"accept": "text/event-stream",
"x-real-ip": "",
"mktunneltype": "http",
"accept-encoding": "gzip, deflate, br",
"mkscheme": "https",
"user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 TitansX/20.0.1.old KNB/1.0 iOS/17.6.1 meituangroup/com.meituan.imeituan-beta/12.24.401 meituangroup/12.24.401 App/10110/12.24.401 iPhone/iPhone12 WKWebView",
"sec-fetch-dest": "empty"
}