mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-04 19:29:49 -06:00
make sse keepalive interval configurable
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
5
changelog/unreleased/sse-keepalive.md
Normal file
5
changelog/unreleased/sse-keepalive.md
Normal file
@@ -0,0 +1,5 @@
|
||||
Bugfix: make SSE keepalive interval configurable
|
||||
|
||||
To prevent intermediate proxies from closing the SSE connection admins can now configure a `SSE_KEEPALIVE_INTERVAL`.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/10411
|
||||
@@ -2,6 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
|
||||
)
|
||||
@@ -14,7 +15,8 @@ type Config struct {
|
||||
Debug Debug `mask:"struct" yaml:"debug"`
|
||||
Tracing *Tracing `yaml:"tracing"`
|
||||
|
||||
Service Service `yaml:"-"`
|
||||
Service Service `yaml:"-"`
|
||||
KeepAliveInterval time.Duration `yaml:"keepalive_interval" env:"SSE_KEEPALIVE_INTERVAL" desc:"To prevent intermediate proxies from closing the SSE connection send periodic SSE comments." introductionVersion:"6.7"`
|
||||
|
||||
Events Events
|
||||
HTTP HTTP `yaml:"http"`
|
||||
|
||||
@@ -2,6 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/r3labs/sse/v2"
|
||||
@@ -81,6 +82,18 @@ func (s SSE) HandleSSE(w http.ResponseWriter, r *http.Request) {
|
||||
stream := s.sse.CreateStream(uid)
|
||||
stream.AutoReplay = false
|
||||
|
||||
if s.c.KeepAliveInterval != 0 {
|
||||
ticker := time.NewTicker(s.c.KeepAliveInterval)
|
||||
defer ticker.Stop()
|
||||
go func() {
|
||||
for range ticker.C {
|
||||
s.sse.Publish(uid, &sse.Event{
|
||||
Comment: []byte("keepalive"),
|
||||
})
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// add stream to URL
|
||||
q := r.URL.Query()
|
||||
q.Set("stream", uid)
|
||||
|
||||
Reference in New Issue
Block a user