mirror of
https://github.com/bolkedebruin/rdpgw.git
synced 2025-07-24 03:20:31 +02:00
Use standard HandleFunc pattern
This commit is contained in:
parent
3ab375314a
commit
1f191a5e41
2 changed files with 20 additions and 26 deletions
2
main.go
2
main.go
|
@ -41,9 +41,9 @@ func main() {
|
|||
cfg.Certificates = append(cfg.Certificates, cert)
|
||||
server := http.Server{
|
||||
Addr: ":" + strconv.Itoa(*port),
|
||||
Handler: Upgrade(nil),
|
||||
TLSConfig: cfg,
|
||||
}
|
||||
http.HandleFunc("/remoteDesktopGateway/", handleGatewayProtocol)
|
||||
|
||||
err = server.ListenAndServeTLS("", "")
|
||||
if err != nil {
|
||||
|
|
8
rdg.go
8
rdg.go
|
@ -110,10 +110,6 @@ var ErrNotHijacker = RejectConnectionError(
|
|||
|
||||
var DefaultSession RdgSession
|
||||
|
||||
func Upgrade(next http.Handler) http.Handler {
|
||||
return handleGatewayProtocol(next)
|
||||
}
|
||||
|
||||
func Accept(w http.ResponseWriter) (conn net.Conn, rw *bufio.ReadWriter, err error) {
|
||||
log.Print("Accept connection")
|
||||
hj, ok := w.(http.Hijacker)
|
||||
|
@ -132,8 +128,7 @@ func Accept(w http.ResponseWriter) (conn net.Conn, rw *bufio.ReadWriter, err err
|
|||
var upgrader = websocket.Upgrader{}
|
||||
var c = cache.New(5*time.Minute, 10*time.Minute)
|
||||
|
||||
func handleGatewayProtocol(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
func handleGatewayProtocol(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == MethodRDGOUT {
|
||||
if r.Header.Get("Connection") != "upgrade" && r.Header.Get("Upgrade") != "websocket" {
|
||||
handleLegacyProtocol(w, r)
|
||||
|
@ -151,7 +146,6 @@ func handleGatewayProtocol(next http.Handler) http.Handler {
|
|||
} else if r.Method == MethodRDGIN {
|
||||
handleLegacyProtocol(w, r)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func handleWebsocketProtocol(conn *websocket.Conn) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue