mirror of
https://github.com/strukturag/nextcloud-spreed-signaling
synced 2024-05-17 13:06:33 +02:00
Merge pull request #644 from strukturag/proxy-welcome
Add "welcome" endpoint to proxy.
This commit is contained in:
commit
beaad80eba
|
@ -26,6 +26,7 @@ import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -82,8 +83,9 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProxyServer struct {
|
type ProxyServer struct {
|
||||||
version string
|
version string
|
||||||
country string
|
country string
|
||||||
|
welcomeMessage string
|
||||||
|
|
||||||
url string
|
url string
|
||||||
mcu signaling.Mcu
|
mcu signaling.Mcu
|
||||||
|
@ -161,9 +163,20 @@ func NewProxyServer(r *mux.Router, version string, config *goconf.ConfigFile) (*
|
||||||
log.Printf("Not sending country information")
|
log.Printf("Not sending country information")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
welcome := map[string]string{
|
||||||
|
"nextcloud-spreed-signaling-proxy": "Welcome",
|
||||||
|
"version": version,
|
||||||
|
}
|
||||||
|
welcomeMessage, err := json.Marshal(welcome)
|
||||||
|
if err != nil {
|
||||||
|
// Should never happen.
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
result := &ProxyServer{
|
result := &ProxyServer{
|
||||||
version: version,
|
version: version,
|
||||||
country: country,
|
country: country,
|
||||||
|
welcomeMessage: string(welcomeMessage) + "\n",
|
||||||
|
|
||||||
shutdownChannel: make(chan struct{}),
|
shutdownChannel: make(chan struct{}),
|
||||||
|
|
||||||
|
@ -197,6 +210,7 @@ func NewProxyServer(r *mux.Router, version string, config *goconf.ConfigFile) (*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.HandleFunc("/welcome", result.setCommonHeaders(result.welcomeHandler)).Methods("GET")
|
||||||
r.HandleFunc("/proxy", result.setCommonHeaders(result.proxyHandler)).Methods("GET")
|
r.HandleFunc("/proxy", result.setCommonHeaders(result.proxyHandler)).Methods("GET")
|
||||||
r.HandleFunc("/stats", result.setCommonHeaders(result.validateStatsRequest(result.statsHandler))).Methods("GET")
|
r.HandleFunc("/stats", result.setCommonHeaders(result.validateStatsRequest(result.statsHandler))).Methods("GET")
|
||||||
r.HandleFunc("/metrics", result.setCommonHeaders(result.validateStatsRequest(result.metricsHandler))).Methods("GET")
|
r.HandleFunc("/metrics", result.setCommonHeaders(result.validateStatsRequest(result.metricsHandler))).Methods("GET")
|
||||||
|
@ -410,6 +424,12 @@ func getRealUserIP(r *http.Request) string {
|
||||||
return r.RemoteAddr
|
return r.RemoteAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ProxyServer) welcomeHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
io.WriteString(w, s.welcomeMessage) // nolint
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ProxyServer) proxyHandler(w http.ResponseWriter, r *http.Request) {
|
func (s *ProxyServer) proxyHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
addr := getRealUserIP(r)
|
addr := getRealUserIP(r)
|
||||||
conn, err := s.upgrader.Upgrade(w, r, nil)
|
conn, err := s.upgrader.Upgrade(w, r, nil)
|
||||||
|
|
Loading…
Reference in a new issue