mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
caddyfile: http and https hosts should render in URL format
This commit is contained in:
parent
976f5182e1
commit
efeeece735
2 changed files with 11 additions and 0 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -104,6 +105,11 @@ func FromJSON(jsonBytes []byte) ([]byte, error) {
|
||||||
|
|
||||||
for _, sb := range j {
|
for _, sb := range j {
|
||||||
for i, host := range sb.Hosts {
|
for i, host := range sb.Hosts {
|
||||||
|
if hostname, port, err := net.SplitHostPort(host); err == nil {
|
||||||
|
if port == "http" || port == "https" {
|
||||||
|
host = port + "://" + hostname
|
||||||
|
}
|
||||||
|
}
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
result += ", "
|
result += ", "
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,11 @@ baz"
|
||||||
}`,
|
}`,
|
||||||
json: `[{"hosts":["host"],"body":{"dir":["123","4.56","true"]}}]`, // NOTE: I guess we assume numbers and booleans should be encoded as strings...?
|
json: `[{"hosts":["host"],"body":{"dir":["123","4.56","true"]}}]`, // NOTE: I guess we assume numbers and booleans should be encoded as strings...?
|
||||||
},
|
},
|
||||||
|
{ // 8
|
||||||
|
caddyfile: `http://host, https://host {
|
||||||
|
}`,
|
||||||
|
json: `[{"hosts":["host:http","host:https"],"body":{}}]`, // hosts in JSON are always host:port format (if port is specified)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestToJSON(t *testing.T) {
|
func TestToJSON(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue