Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
Don't append port to unix sockets
See https://caddy.community/t/caddy-v2-php-fpm-502-error/6571?u=matt
Matthew Holt committed
Dec 6, 2019 at 11:45 UTC
33a318d17341fcaa95551710620540e00b0bb4b0
2 files changed
+63
-1
listeners.go
+14
-1
@@ -266,9 +266,18 @@ type ParsedAddress struct {
266
EndPort uint
267
}
268
269
+// IsUnixNetwork returns true if pa.Network is
270
+// unix, unixgram, or unixpacket.
271
+func (pa ParsedAddress) IsUnixNetwork() bool {
272
+ return isUnixNetwork(pa.Network)
273
+}
274
+
275
// JoinHostPort is like net.JoinHostPort, but where the port
276
// is StartPort + offset.
277
func (pa ParsedAddress) JoinHostPort(offset uint) string {
278
+ if pa.IsUnixNetwork() {
279
+ return pa.Host
280
+ }
281
return net.JoinHostPort(pa.Host, strconv.Itoa(int(pa.StartPort+offset)))
282
}
283
@@ -290,6 +299,10 @@ func (pa ParsedAddress) String() string {
299
return JoinNetworkAddress(pa.Network, pa.Host, port)
300
}
301
302
+func isUnixNetwork(netw string) bool {
303
+ return netw == "unix" || netw == "unixgram" || netw == "unixpacket"
304
+}
305
+
306
// ParseNetworkAddress parses addr into its individual
307
// components. The input string is expected to be of
308
// the form "network/host:port-range" where any part is
@@ -307,7 +320,7 @@ func ParseNetworkAddress(addr string) (ParsedAddress, error) {
320
if err != nil {
321
return ParsedAddress{}, err
322
}
310
- if network == "unix" || network == "unixgram" || network == "unixpacket" {
323
+ if isUnixNetwork(network) {
324
return ParsedAddress{
325
Network: network,
326
Host: host,
listeners_test.go
+49
@@ -250,3 +250,52 @@ func TestParseNetworkAddress(t *testing.T) {
250
}
251
}
252
}
253
+
254
+func TestJoinHostPort(t *testing.T) {
255
+ for i, tc := range []struct {
256
+ pa ParsedAddress
257
+ offset uint
258
+ expect string
259
+ }{
260
+ {
261
+ pa: ParsedAddress{
262
+ Network: "tcp",
263
+ Host: "localhost",
264
+ StartPort: 1234,
265
+ EndPort: 1234,
266
+ },
267
+ expect: "localhost:1234",
268
+ },
269
+ {
270
+ pa: ParsedAddress{
271
+ Network: "tcp",
272
+ Host: "localhost",
273
+ StartPort: 1234,
274
+ EndPort: 1235,
275
+ },
276
+ expect: "localhost:1234",
277
+ },
278
+ {
279
+ pa: ParsedAddress{
280
+ Network: "tcp",
281
+ Host: "localhost",
282
+ StartPort: 1234,
283
+ EndPort: 1235,
284
+ },
285
+ offset: 1,
286
+ expect: "localhost:1235",
287
+ },
288
+ {
289
+ pa: ParsedAddress{
290
+ Network: "unix",
291
+ Host: "/run/php/php7.3-fpm.sock",
292
+ },
293
+ expect: "/run/php/php7.3-fpm.sock",
294
+ },
295
+ } {
296
+ actual := tc.pa.JoinHostPort(tc.offset)
297
+ if actual != tc.expect {
298
+ t.Errorf("Test %d: Expected '%s' but got '%s'", i, tc.expect, actual)
299
+ }
300
+ }
301
+}