Support https

This commit is contained in:
Daniel 2024-10-21 23:19:56 -04:00
parent 334c509f8b
commit c081e37a97

View file

@ -28,12 +28,21 @@ var (
addr = flag.String("addr", "localhost:8080", "http service address")
username = flag.String("user", "", "username")
password = flag.String("password", "", "password")
secure = flag.Bool("s", false, "secure (https/wss)")
)
func main() {
flag.Parse()
log.SetFlags(0)
secureSuffix := func() string {
if *secure {
return "s"
}
return ""
}
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
play := NewPlayer()
@ -42,7 +51,7 @@ func main() {
loginForm.Add("username", *username)
loginForm.Add("password", *password)
loginReq, err := http.NewRequest("POST", "http://"+*addr+"/login", strings.NewReader(loginForm.Encode()))
loginReq, err := http.NewRequest("POST", "http"+secureSuffix()+"://"+*addr+"/login", strings.NewReader(loginForm.Encode()))
if err != nil {
log.Fatal(err)
}
@ -72,7 +81,7 @@ func main() {
log.Fatal(err)
}
u := url.URL{Scheme: "ws", Host: *addr, Path: "/ws"}
u := url.URL{Scheme: "ws"+secureSuffix(), Host: *addr, Path: "/ws"}
log.Printf("connecting to %s", u.String())
dialer := websocket.Dialer{