commit 6d8b508ace60e4f1c7ae4c80a77f5ecbab04bdf5
parent e5f519481b32562c334b3ad83c3bf76af062a354
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Mon, 11 Dec 2023 15:08:50 -0500
cleanup
Diffstat:
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -1838,10 +1838,7 @@ func PokerLogsHandler(c echo.Context) error {
sub := PokerPubSub.Subscribe([]string{roomLogsTopic})
defer sub.Close()
quit := hutils.CloseSignalChan(c)
- c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTMLCharsetUTF8)
- c.Response().WriteHeader(http.StatusOK)
- c.Response().Header().Set("Transfer-Encoding", "chunked")
- c.Response().Header().Set("Connection", "keep-alive")
+ hutils.SetStreamingHeaders(c)
send(cssReset)
send(`<style>body { background-color: #ccc; }</style><div style="display:flex;flex-direction:column-reverse;">`)
@@ -1890,17 +1887,13 @@ func PokerHandler(c echo.Context) error {
}
quit := hutils.CloseSignalChan(c)
+ hutils.SetStreamingHeaders(c)
roomTopic := "room_" + roomID
roomUserTopic := "room_" + roomID + "_" + authUser.Username.String()
sub := PokerPubSub.Subscribe([]string{roomTopic, roomUserTopic})
defer sub.Close()
- c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTMLCharsetUTF8)
- c.Response().WriteHeader(http.StatusOK)
- c.Response().Header().Set("Transfer-Encoding", "chunked")
- c.Response().Header().Set("Connection", "keep-alive")
-
send(buildBaseHtml(g, authUser, roomID))
c.Response().Flush()
diff --git a/pkg/web/handlers/utils/utils.go b/pkg/web/handlers/utils/utils.go
@@ -190,6 +190,13 @@ func VerifyPow(username, nonce string, difficulty int) bool {
return strings.HasPrefix(hashed, prefix)
}
+func SetStreamingHeaders(c echo.Context) {
+ c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTMLCharsetUTF8)
+ c.Response().WriteHeader(http.StatusOK)
+ c.Response().Header().Set("Transfer-Encoding", "chunked")
+ c.Response().Header().Set("Connection", "keep-alive")
+}
+
func CloseSignalChan(c echo.Context) <-chan struct{} {
ctx, cancel := context.WithCancel(context.Background())
// Listen to the closing of HTTP connection via CloseNotifier