1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-08-10 08:10:52 +00:00

can't believe i didn't already have this smdh

This commit is contained in:
Kane York 2015-10-26 18:00:29 -07:00
parent 8ba87e1a27
commit a6508d32ab
2 changed files with 27 additions and 2 deletions

View file

@ -297,7 +297,7 @@ func GetCommandsOfType(match PushCommandCacheInfo) []Command {
return ret
}
func HBackendDumpCache(w http.ResponseWriter, r *http.Request) {
func HBackendDumpBacklog(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
formData, err := UnsealRequest(r.Form)
if err != nil {

View file

@ -11,6 +11,7 @@ import (
"strconv"
"strings"
"sync"
"html/template"
)
const MAX_PACKET_SIZE = 1024
@ -125,11 +126,35 @@ func SetupServerAndHandle(config *Config, tlsConfig *tls.Config, serveMux *http.
if serveMux == nil {
serveMux = http.DefaultServeMux
}
serveMux.HandleFunc("/", sockServer.ServeHTTP)
serveMux.HandleFunc("/", ServeWebsocketOrCatbag(sockServer.ServeHTTP))
serveMux.HandleFunc("/pub_msg", HBackendPublishRequest)
serveMux.HandleFunc("/dump_backlog", HBackendDumpBacklog)
serveMux.HandleFunc("/update_and_pub", HBackendUpdateAndPublish)
}
var Catbag = template.Must(template.New(`
<!DOCTYPE html>
<html>
<head>
<title>CatBag</title>
</head>
<body>
</body>
</html>
`).Parse("html"))
func ServeWebsocketOrCatbag(sockfunc func(http.ResponseWriter, *http.Request)) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Connection") == "Upgrade" {
sockfunc(w, r)
return
} else {
Catbag.Execute(w, nil)
}
}
}
// Handle a new websocket connection from a FFZ client.
// This runs in a goroutine started by net/http.
func HandleSocketConnection(conn *websocket.Conn) {