This commit is contained in:
parent
dd668e035f
commit
885be2b2ab
1 changed files with 19 additions and 6 deletions
25
main.go
25
main.go
|
@ -304,6 +304,8 @@ func RelativeUrl(in string) (newurl string) {
|
|||
func main() {
|
||||
var sock string
|
||||
var port string
|
||||
var cert string
|
||||
var key string
|
||||
|
||||
path_prefix = os.Getenv("PREFIX_PATH")
|
||||
|
||||
|
@ -319,14 +321,13 @@ func main() {
|
|||
// }
|
||||
// }
|
||||
|
||||
flag.StringVar(&sock, "s", "/run/http-proxy.sock", "Specify a socket name")
|
||||
flag.StringVar(&cert, "tls-cert", "", "TLS Certificate path")
|
||||
flag.StringVar(&key, "tls-key", "", "TLS Certificate Key path")
|
||||
var https = flag.Bool("https", false, "Use built-in https server")
|
||||
flag.StringVar(&sock, "s", "/tmp/http-ytproxy.sock", "Specify a socket name")
|
||||
flag.StringVar(&port, "p", "8080", "Specify a port number")
|
||||
flag.Parse()
|
||||
|
||||
socket := string(sock)
|
||||
syscall.Unlink(socket)
|
||||
listener, err := net.Listen("unix", socket)
|
||||
|
||||
srv := &http.Server{
|
||||
ReadTimeout: 5 * time.Second,
|
||||
WriteTimeout: 1 * time.Hour,
|
||||
|
@ -334,6 +335,10 @@ func main() {
|
|||
Handler: &requesthandler{},
|
||||
}
|
||||
|
||||
socket := string(sock)
|
||||
syscall.Unlink(socket)
|
||||
listener, err := net.Listen("unix", socket)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Failed to bind to UDS, please check the socket name, falling back to TCP/IP")
|
||||
fmt.Println(err.Error())
|
||||
|
@ -353,6 +358,14 @@ func main() {
|
|||
fmt.Println("Setting socket permissions to 777")
|
||||
}
|
||||
go srv.Serve(listener)
|
||||
srv.ListenAndServe()
|
||||
if *https {
|
||||
if err := srv.ListenAndServeTLS(cert, key); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println("Serving HTTPS")
|
||||
} else {
|
||||
fmt.Println("Serving HTTP")
|
||||
srv.ListenAndServe()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue