mirror of
https://github.com/willnorris/imageproxy.git
synced 2025-01-13 22:51:38 -05:00
Add support for UNIX domain socket
Allows listening to UNIX domain socket with the `-addr` option. The syntax is `unix:path`. (same as NGINX `listen` directive)
This commit is contained in:
parent
c08b3c505a
commit
bbb9acad8d
1 changed files with 19 additions and 8 deletions
|
@ -20,6 +20,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -43,7 +44,7 @@ import (
|
||||||
|
|
||||||
const defaultMemorySize = 100
|
const defaultMemorySize = 100
|
||||||
|
|
||||||
var addr = flag.String("addr", "localhost:8080", "TCP address to listen on")
|
var addr = flag.String("addr", "localhost:8080", "address to listen on, could be either a TCP address or a UNIX domain socket path prefixed with unix:")
|
||||||
var allowHosts = flag.String("allowHosts", "", "comma separated list of allowed remote hosts")
|
var allowHosts = flag.String("allowHosts", "", "comma separated list of allowed remote hosts")
|
||||||
var denyHosts = flag.String("denyHosts", "", "comma separated list of denied remote hosts")
|
var denyHosts = flag.String("denyHosts", "", "comma separated list of denied remote hosts")
|
||||||
var referrers = flag.String("referrers", "", "comma separated list of allowed referring hosts")
|
var referrers = flag.String("referrers", "", "comma separated list of allowed referring hosts")
|
||||||
|
@ -97,15 +98,25 @@ func main() {
|
||||||
p.Verbose = *verbose
|
p.Verbose = *verbose
|
||||||
p.UserAgent = *userAgent
|
p.UserAgent = *userAgent
|
||||||
|
|
||||||
server := &http.Server{
|
|
||||||
Addr: *addr,
|
|
||||||
Handler: p,
|
|
||||||
}
|
|
||||||
|
|
||||||
r := mux.NewRouter().SkipClean(true).UseEncodedPath()
|
r := mux.NewRouter().SkipClean(true).UseEncodedPath()
|
||||||
r.PathPrefix("/").Handler(p)
|
r.PathPrefix("/").Handler(p)
|
||||||
fmt.Printf("imageproxy listening on %s\n", server.Addr)
|
|
||||||
log.Fatal(http.ListenAndServe(*addr, r))
|
fmt.Printf("imageproxy listening on %s\n", *addr)
|
||||||
|
|
||||||
|
var listener net.Listener
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if strings.HasPrefix(*addr, "unix:") {
|
||||||
|
listener, err = net.Listen("unix", (*addr)[5:])
|
||||||
|
} else {
|
||||||
|
listener, err = net.Listen("tcp", *addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("listen failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Fatal(http.Serve(listener, r))
|
||||||
}
|
}
|
||||||
|
|
||||||
type signatureKeyList [][]byte
|
type signatureKeyList [][]byte
|
||||||
|
|
Loading…
Add table
Reference in a new issue