lol
This commit is contained in:
parent
4638cf35e0
commit
e6b59e4ff1
33
main.go
33
main.go
@ -1,11 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -22,6 +25,30 @@ type KeyPress struct {
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
type gzipResponseWriter struct {
|
||||
io.Writer
|
||||
http.ResponseWriter
|
||||
}
|
||||
|
||||
func (w gzipResponseWriter) Write(b []byte) (int, error) {
|
||||
return w.Writer.Write(b)
|
||||
}
|
||||
|
||||
func gzipHandler(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
|
||||
next(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
gz := gzip.NewWriter(w)
|
||||
defer gz.Close()
|
||||
|
||||
w.Header().Set("Content-Encoding", "gzip")
|
||||
next(gzipResponseWriter{Writer: gz, ResponseWriter: w}, r)
|
||||
}
|
||||
}
|
||||
|
||||
func wsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
conn, err := upgrader.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
@ -257,10 +284,10 @@ func main() {
|
||||
go func(p string) {
|
||||
defer wg.Done()
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", handler)
|
||||
mux.HandleFunc("/", gzipHandler(handler))
|
||||
mux.HandleFunc("/ws", wsHandler)
|
||||
mux.HandleFunc("/status", statusHandler)
|
||||
mux.HandleFunc("/trolling", trollingHandler)
|
||||
mux.HandleFunc("/status", gzipHandler(statusHandler))
|
||||
mux.HandleFunc("/trolling", gzipHandler(trollingHandler))
|
||||
|
||||
server := &http.Server{
|
||||
Addr: ":" + p,
|
||||
|
Loading…
x
Reference in New Issue
Block a user