跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

lifecycle_http.go

28 行 · 771 B历史下载
1package workbench
2
3import (
4 "context"
5 "net/http"
6 "time"
7)
8
9// Cancelling a context alone cannot release a slow request-body read or a
10// response write. HTTP deadlines interrupt both without closing a reused
11// connection after its handler has returned. A genuine upgrade also owns its
12// WebSocket cancellation; an Upgrade header alone must not bypass body cleanup.
13func interruptHTTPOnCancel(w http.ResponseWriter, r *http.Request) func() {
14 done := make(chan struct{})
15 body := r.Body
16 stop := context.AfterFunc(r.Context(), func() {
17 defer close(done)
18 controller := http.NewResponseController(w)
19 _ = controller.SetReadDeadline(time.Now())
20 _ = controller.SetWriteDeadline(time.Now())
21 _ = body.Close()
22 })
23 return func() {
24 if !stop() {
25 <-done
26 }
27 }
28}