Skip to content

Add support for UNIX domain socket #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions cmd/imageproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"flag"
"fmt"
"log"
"net"
"net/http"
"net/url"
"os"
Expand All @@ -30,7 +31,7 @@

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, 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 denyHosts = flag.String("denyHosts", "", "comma separated list of denied remote hosts")
var referrers = flag.String("referrers", "", "comma separated list of allowed referring hosts")
Expand Down Expand Up @@ -92,6 +93,18 @@
p.MinimumCacheDuration = *minCacheDuration
p.ForceCache = *forceCache

var ln net.Listener
var err error

if path, ok := strings.CutPrefix(*addr, "unix:"); ok {
ln, err = net.Listen("unix", path)
} else {
ln, err = net.Listen("tcp", *addr)
}
if err != nil {
log.Fatalf("listen failed: %v", err)
}

Check warning on line 106 in cmd/imageproxy/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/imageproxy/main.go#L96-L106

Added lines #L96 - L106 were not covered by tests

server := &http.Server{
Addr: *addr,
Handler: p,
Expand All @@ -101,8 +114,8 @@
IdleTimeout: 120 * time.Second,
}

fmt.Printf("imageproxy listening on %s\n", server.Addr)
log.Fatal(server.ListenAndServe())
fmt.Printf("imageproxy listening on %s\n", *addr)
log.Fatal(server.Serve(ln))

Check warning on line 118 in cmd/imageproxy/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/imageproxy/main.go#L117-L118

Added lines #L117 - L118 were not covered by tests
}

type signatureKeyList [][]byte
Expand Down
Loading