Skip to content

Commit 48f63f8

Browse files
committed
Let curl decide the default scheme when it is omitted
Fixes #89
1 parent 56211ba commit 48f63f8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

args/httpie.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,16 @@ func parseFancyArgs(args []string, postMode PostMode) (opts Opts) {
7373

7474
func normalizeURL(u string) string {
7575
// If scheme is omitted, use http:
76+
noScheme := false
7677
if !strings.HasPrefix(u, "http") {
7778
if strings.HasPrefix(u, "//") {
7879
u = "http:" + u
7980
} else {
8081
u = "http://" + u
8182
}
83+
noScheme = true
8284
}
85+
println(u)
8386
pu, err := url.Parse(u)
8487
if err != nil {
8588
fmt.Print(err)
@@ -91,7 +94,13 @@ func normalizeURL(u string) string {
9194
// If :port is given with no hostname, add localhost
9295
pu.Host = "localhost" + pu.Host
9396
}
94-
return pu.String()
97+
nu := pu.String()
98+
if noScheme {
99+
// Remove the prefixed scheme added above so we let curl handle deal
100+
// with the default scheme (ie if --proto-default is used)
101+
nu = strings.TrimPrefix(nu, "http://")
102+
}
103+
return nu
95104
}
96105

97106
func parseArg(arg string) (typ argType, name, value string) {

0 commit comments

Comments
 (0)