diff options
author | 2023-01-08 11:43:08 +0000 | |
---|---|---|
committer | 2023-01-08 11:43:08 +0000 | |
commit | 1bda6a2002b18d3732b24d2496b88e137a32968b (patch) | |
tree | 8bfb104d9e7e7035f8ccfb355078466096456ab8 /internal/api/client/streaming/streaming.go | |
parent | [docs] Rewrite sponsorship + funding section, add NLnet (#1305) (diff) | |
download | gotosocial-1bda6a2002b18d3732b24d2496b88e137a32968b.tar.xz |
[bugfix] return early in websocket upgrade handler (#1315)
* launch websocket streaming in goroutine to allow upgrade handler to return
* don't send any message on ping, improved close check on failed read
* use context to signal wsconn close, ensure canceled in read goroutine
Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/api/client/streaming/streaming.go')
-rw-r--r-- | internal/api/client/streaming/streaming.go | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/internal/api/client/streaming/streaming.go b/internal/api/client/streaming/streaming.go index c23f03c81..d4c61f7a0 100644 --- a/internal/api/client/streaming/streaming.go +++ b/internal/api/client/streaming/streaming.go @@ -23,6 +23,7 @@ import ( "time" "github.com/gin-gonic/gin" + "github.com/gorilla/websocket" "github.com/superseriousbusiness/gotosocial/internal/processing" ) @@ -41,21 +42,22 @@ const ( ) type Module struct { - processor processing.Processor - tickDuration time.Duration + processor processing.Processor + dTicker time.Duration + wsUpgrade websocket.Upgrader } -func New(processor processing.Processor) *Module { +func New(processor processing.Processor, dTicker time.Duration, wsBuf int) *Module { return &Module{ - processor: processor, - tickDuration: 30 * time.Second, - } -} + processor: processor, + dTicker: dTicker, + wsUpgrade: websocket.Upgrader{ + ReadBufferSize: wsBuf, // we don't expect reads + WriteBufferSize: wsBuf, -func NewWithTickDuration(processor processing.Processor, tickDuration time.Duration) *Module { - return &Module{ - processor: processor, - tickDuration: tickDuration, + // we expect cors requests (via eg., pinafore.social) so be lenient + CheckOrigin: func(r *http.Request) bool { return true }, + }, } } |