make sse keepalive interval configurable
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
@@ -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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
|
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
|
||||||
)
|
)
|
||||||
@@ -14,7 +15,8 @@ type Config struct {
|
|||||||
Debug Debug `mask:"struct" yaml:"debug"`
|
Debug Debug `mask:"struct" yaml:"debug"`
|
||||||
Tracing *Tracing `yaml:"tracing"`
|
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
|
Events Events
|
||||||
HTTP HTTP `yaml:"http"`
|
HTTP HTTP `yaml:"http"`
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/r3labs/sse/v2"
|
"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 := s.sse.CreateStream(uid)
|
||||||
stream.AutoReplay = false
|
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
|
// add stream to URL
|
||||||
q := r.URL.Query()
|
q := r.URL.Query()
|
||||||
q.Set("stream", uid)
|
q.Set("stream", uid)
|
||||||
|
|||||||
Reference in New Issue
Block a user