Skip to content

Commit 97f37f1

Browse files
committed
fix: error if protocol isn't specified in --access-url
1 parent a7e5588 commit 97f37f1

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

cli/server.go

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
225225
cfg.AccessURL.Value = tunnel.URL
226226

227227
if cfg.WildcardAccessURL.Value == "" {
228-
u, err := parseURL(ctx, tunnel.URL)
228+
u, err := parseURL(tunnel.URL)
229229
if err != nil {
230230
return xerrors.Errorf("parse tunnel url: %w", err)
231231
}
@@ -235,7 +235,7 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
235235
}
236236
}
237237

238-
accessURLParsed, err := parseURL(ctx, cfg.AccessURL.Value)
238+
accessURLParsed, err := parseURL(cfg.AccessURL.Value)
239239
if err != nil {
240240
return xerrors.Errorf("parse URL: %w", err)
241241
}
@@ -469,7 +469,7 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
469469
}
470470

471471
// Parse the raw telemetry URL!
472-
telemetryURL, err := parseURL(ctx, cfg.Telemetry.URL.Value)
472+
telemetryURL, err := parseURL(cfg.Telemetry.URL.Value)
473473
if err != nil {
474474
return xerrors.Errorf("parse telemetry url: %w", err)
475475
}
@@ -779,34 +779,21 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
779779
return root
780780
}
781781

782-
// parseURL parses a string into a URL. It works around some technically correct
783-
// but undesired behavior of url.Parse by prepending a scheme if one does not
784-
// exist so that the URL does not get parsed improperly.
785-
func parseURL(ctx context.Context, u string) (*url.URL, error) {
782+
// parseURL parses a string into a URL.
783+
func parseURL(u string) (*url.URL, error) {
786784
var (
787785
hasScheme = strings.HasPrefix(u, "http:") || strings.HasPrefix(u, "https:")
788786
)
789787

790788
if !hasScheme {
791-
// Append a scheme if it doesn't have one. Otherwise the hostname
792-
// will likely get parsed as the scheme and cause methods like Hostname()
793-
// to return an empty string, largely obviating the purpose of this
794-
// function.
795-
u = "https://" + u
789+
return nil, xerrors.Errorf("URL %q must have a scheme of either http or https", u)
796790
}
797791

798792
parsed, err := url.Parse(u)
799793
if err != nil {
800794
return nil, err
801795
}
802796

803-
// If the specified url is a loopback device and no scheme has been
804-
// specified, prefer http over https. It's unlikely anyone intends to use
805-
// https on a loopback and if they do they can specify a scheme.
806-
if local, _ := isLocalURL(ctx, parsed); local && !hasScheme {
807-
parsed.Scheme = "http"
808-
}
809-
810797
return parsed, nil
811798
}
812799

0 commit comments

Comments
 (0)