mirror of
https://github.com/gin-gonic/gin.git
synced 2026-07-13 14:41:33 +08:00
Compare commits
3 Commits
95358a8d2b
...
cd83745918
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd83745918 | ||
|
|
e88fc8927a | ||
|
|
2591a34c1d |
5
.github/workflows/trivy-scan.yml
vendored
5
.github/workflows/trivy-scan.yml
vendored
@ -8,9 +8,8 @@ on:
|
||||
branches:
|
||||
- master
|
||||
schedule:
|
||||
# Run every 3 months (quarterly) on the 1st day at 00:00 UTC
|
||||
# Months: January (1), April (4), July (7), October (10)
|
||||
- cron: '0 0 1 1,4,7,10 *'
|
||||
# Run daily at 00:00 UTC
|
||||
- cron: '0 0 * * *'
|
||||
workflow_dispatch: # Allow manual trigger
|
||||
|
||||
permissions:
|
||||
|
||||
@ -1298,10 +1298,9 @@ func (c *Context) SSEvent(name string, message any) {
|
||||
// indicates "Is client disconnected in middle of stream"
|
||||
func (c *Context) Stream(step func(w io.Writer) bool) bool {
|
||||
w := c.Writer
|
||||
clientGone := w.CloseNotify()
|
||||
for {
|
||||
select {
|
||||
case <-clientGone:
|
||||
case <-c.Request.Context().Done():
|
||||
return true
|
||||
default:
|
||||
keepOpen := step(w)
|
||||
|
||||
@ -2917,10 +2917,6 @@ func (r *TestResponseRecorder) CloseNotify() <-chan bool {
|
||||
return r.closeChannel
|
||||
}
|
||||
|
||||
func (r *TestResponseRecorder) closeClient() {
|
||||
r.closeChannel <- true
|
||||
}
|
||||
|
||||
func CreateTestResponseRecorder() *TestResponseRecorder {
|
||||
return &TestResponseRecorder{
|
||||
httptest.NewRecorder(),
|
||||
@ -2931,6 +2927,7 @@ func CreateTestResponseRecorder() *TestResponseRecorder {
|
||||
func TestContextStream(t *testing.T) {
|
||||
w := CreateTestResponseRecorder()
|
||||
c, _ := CreateTestContext(w)
|
||||
c.Request, _ = http.NewRequest(http.MethodGet, "", nil)
|
||||
|
||||
stopStream := true
|
||||
c.Stream(func(w io.Writer) bool {
|
||||
@ -2950,10 +2947,12 @@ func TestContextStream(t *testing.T) {
|
||||
func TestContextStreamWithClientGone(t *testing.T) {
|
||||
w := CreateTestResponseRecorder()
|
||||
c, _ := CreateTestContext(w)
|
||||
done, cancel := context.WithCancel(context.Background())
|
||||
c.Request, _ = http.NewRequestWithContext(done, http.MethodGet, "", nil)
|
||||
|
||||
c.Stream(func(writer io.Writer) bool {
|
||||
defer func() {
|
||||
w.closeClient()
|
||||
cancel()
|
||||
}()
|
||||
|
||||
_, err := writer.Write([]byte("test"))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user