fix3
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m42s
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m42s
This commit is contained in:
16
main.go
16
main.go
@@ -109,17 +109,25 @@ func main() {
|
|||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/room/", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/room/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
// Обязательный заголовок для браузера
|
// 1. Обязательно даем понять браузеру, что тут есть HTTP/3 (UDP 443)
|
||||||
w.Header().Set("Alt-Svc", `h3=":443"; ma=2592000`)
|
w.Header().Set("Alt-Svc", `h3=":443"; ma=86400`)
|
||||||
|
|
||||||
roomName := strings.TrimPrefix(r.URL.Path, "/room/")
|
// 2. Если это не CONNECT (не WebTransport), а обычный GET
|
||||||
|
if r.Method != http.MethodConnect {
|
||||||
|
log.Printf("Received GET request on %s. Sending Alt-Svc to client...", r.URL.Path)
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.Write([]byte("To use WebTransport, the browser needs to see this Alt-Svc header first. Try connecting again now."))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Попытка апгрейда
|
// 3. Если это CONNECT, пробуем апгрейд
|
||||||
sess, err := wt.Upgrade(w, r)
|
sess, err := wt.Upgrade(w, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Upgrade error: %v", err)
|
log.Printf("Upgrade error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
roomName := strings.TrimPrefix(r.URL.Path, "/room/")
|
||||||
go server.handleSession(roomName, sess)
|
go server.handleSession(roomName, sess)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user