This commit is contained in:
parent
4675521ffa
commit
128dfafe48
1 changed files with 19 additions and 10 deletions
29
main.go
29
main.go
|
@ -310,28 +310,30 @@ func main() {
|
||||||
disable_ipv6 = os.Getenv("DISABLE_IPV6") == "1"
|
disable_ipv6 = os.Getenv("DISABLE_IPV6") == "1"
|
||||||
disable_webp = os.Getenv("DISABLE_WEBP") == "1"
|
disable_webp = os.Getenv("DISABLE_WEBP") == "1"
|
||||||
|
|
||||||
if _, err := os.Stat("socket"); os.IsNotExist(err) {
|
// if _, err := os.Stat("socket"); os.IsNotExist(err) {
|
||||||
fmt.Println("socket folder doesn't exists, creating one now.")
|
// fmt.Println("socket folder doesn't exists, creating one now.")
|
||||||
err = os.Mkdir("socket", 0755)
|
// err = os.Mkdir("socket", 0777)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
fmt.Println("Failed to create folder, error: ")
|
// fmt.Println("Failed to create folder, error: ")
|
||||||
log.Fatal(err)
|
// log.Fatal(err)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
flag.StringVar(&sock, "s", "http-proxy.sock", "Specify a socket name")
|
flag.StringVar(&sock, "s", "/tmp/http-proxy.sock", "Specify a socket name")
|
||||||
flag.StringVar(&port, "p", "8080", "Specify a port number")
|
flag.StringVar(&port, "p", "8080", "Specify a port number")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
socket := "socket" + string(os.PathSeparator) + string(sock)
|
socket := string(sock)
|
||||||
syscall.Unlink(socket)
|
syscall.Unlink(socket)
|
||||||
listener, err := net.Listen("unix", socket)
|
listener, err := net.Listen("unix", socket)
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
ReadTimeout: 5 * time.Second,
|
ReadTimeout: 5 * time.Second,
|
||||||
WriteTimeout: 1 * time.Hour,
|
WriteTimeout: 1 * time.Hour,
|
||||||
Addr: ":" + string(port),
|
Addr: ":" + string(port),
|
||||||
Handler: &requesthandler{},
|
Handler: &requesthandler{},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Failed to bind to UDS, please check the socket name, falling back to TCP/IP")
|
fmt.Println("Failed to bind to UDS, please check the socket name, falling back to TCP/IP")
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
|
@ -344,4 +346,11 @@ func main() {
|
||||||
defer listener.Close()
|
defer listener.Close()
|
||||||
srv.ListenAndServe()
|
srv.ListenAndServe()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To allow everyone to access the socket
|
||||||
|
err = os.Chmod(socket, 0777)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error setting permissions:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue