{"id":15679950,"url":"https://github.com/cgqaq/chatgpt-sse-hide-example","last_synced_at":"2025-05-07T10:04:00.547Z","repository":{"id":112887056,"uuid":"602943586","full_name":"CGQAQ/chatgpt-sse-hide-example","owner":"CGQAQ","description":"ChatGPT web端看不到响应数据的原理及例子","archived":false,"fork":false,"pushed_at":"2023-02-20T01:14:41.000Z","size":14,"stargazers_count":29,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T10:01:59.613Z","etag":null,"topics":["api","chatgpt","chatgpt-web","chatgpt3","under-the-hood"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CGQAQ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-17T09:26:52.000Z","updated_at":"2025-01-11T09:02:29.000Z","dependencies_parsed_at":"2023-09-19T03:47:45.670Z","dependency_job_id":null,"html_url":"https://github.com/CGQAQ/chatgpt-sse-hide-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CGQAQ%2Fchatgpt-sse-hide-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CGQAQ%2Fchatgpt-sse-hide-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CGQAQ%2Fchatgpt-sse-hide-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CGQAQ%2Fchatgpt-sse-hide-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CGQAQ","download_url":"https://codeload.github.com/CGQAQ/chatgpt-sse-hide-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252856550,"owners_count":21814858,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","chatgpt","chatgpt-web","chatgpt3","under-the-hood"],"created_at":"2024-10-03T16:39:18.791Z","updated_at":"2025-05-07T10:04:00.485Z","avatar_url":"https://github.com/CGQAQ.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chatgpt网页版看不到响应数据的原理及例子\n\n如图：\n![image](https://user-images.githubusercontent.com/15936231/219986461-790833d3-079e-4176-a08f-e85b630e74bd.png)\n![image](https://user-images.githubusercontent.com/15936231/219986490-0331ebbb-cbd4-4490-8422-a3e743d60926.png)\n是收到了响应数据的，有5.8 KB，但是 EventStream 却什么都没有。\n\n一开始确实毫无头绪，但 [@phodal][phodal] 给出了思路，觉得是一些 http 的奇技淫巧，后来我顺着这个思路找下去发现不可能是 http 层面的问题，因为 [spec][spec] 说明如果不是 event、data、id 或 retry 就会被浏览器丢掉，js 没有机会做骚操作，我又翻了下 [webkit 的源码][webkit eventsource] 佐证了这一事实：浏览器并没有特殊实现，完全按照 spec 来的\n![image](https://user-images.githubusercontent.com/15936231/219986725-82690528-ba21-4949-8383-b4e46f2e9b5c.png)\n\n\n最后经过研究发现其实服务端并没有进行什么骚操作，只是浏览器端使用了[server-sent-event(sse)][sse], 但是没有用标准的 EventSource，而是自己fetch，只不过 `request header` 加上了 ['Accept': 'text/event-stream'][fetch]. 具体操作可以看本仓库示例\n\n\n[phodal]: https://github.com/phodal\n[webkit eventsource]: https://github.com/WebKit/webkit/blob/main/Source/WebCore/page/EventSource.cpp#L371-L388\n[sse]: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events\n[fetch]: https://github.com/CGQAQ/chatgpt-sse-hide-example/blob/b5f673ad57a0b987291f9eca4ef35e67e1b6f479/index.html#L11\n[spec]: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcgqaq%2Fchatgpt-sse-hide-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcgqaq%2Fchatgpt-sse-hide-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcgqaq%2Fchatgpt-sse-hide-example/lists"}