Skip to content

Commit

Permalink
Merge pull request #644 from strukturag/proxy-welcome
Browse files Browse the repository at this point in the history
Add "welcome" endpoint to proxy.
  • Loading branch information
fancycode authored Jan 24, 2024
2 parents a362682 + 59cf86d commit beaad80
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions proxy/proxy_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"crypto/rand"
"encoding/json"
"fmt"
"io"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -82,8 +83,9 @@ var (
)

type ProxyServer struct {
version string
country string
version string
country string
welcomeMessage string

url string
mcu signaling.Mcu
Expand Down Expand Up @@ -161,9 +163,20 @@ func NewProxyServer(r *mux.Router, version string, config *goconf.ConfigFile) (*
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{
version: version,
country: country,
version: version,
country: country,
welcomeMessage: string(welcomeMessage) + "\n",

shutdownChannel: make(chan struct{}),

Expand Down Expand Up @@ -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("/stats", result.setCommonHeaders(result.validateStatsRequest(result.statsHandler))).Methods("GET")
r.HandleFunc("/metrics", result.setCommonHeaders(result.validateStatsRequest(result.metricsHandler))).Methods("GET")
Expand Down Expand Up @@ -410,6 +424,12 @@ func getRealUserIP(r *http.Request) string {
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) {
addr := getRealUserIP(r)
conn, err := s.upgrader.Upgrade(w, r, nil)
Expand Down

0 comments on commit beaad80

Please sign in to comment.