Commit efeeece7 authored by Matthew Holt's avatar Matthew Holt

caddyfile: http and https hosts should render in URL format

parent 976f5182
......@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"net"
"strconv"
"strings"
......@@ -104,6 +105,11 @@ func FromJSON(jsonBytes []byte) ([]byte, error) {
for _, sb := range j {
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 {
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...?
},
{ // 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) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment