Skip to content

Commit 1713666

Browse files
sago35deadprogram
authored andcommitted
net/http: Fix http.Get() with port specification
1 parent ca34b93 commit 1713666

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

net/http/tinygo.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,16 @@ func (c *Client) doHTTP(req *Request) (*Response, error) {
3838
}
3939

4040
// make TCP connection
41-
ip := net.ParseIP(req.URL.Host)
42-
raddr := &net.TCPAddr{IP: ip, Port: 80}
41+
ip := net.ParseIP(req.URL.Hostname())
42+
port := 80
43+
if req.URL.Port() != "" {
44+
p, err := strconv.ParseUint(req.URL.Port(), 0, 64)
45+
if err != nil {
46+
return nil, err
47+
}
48+
port = int(p)
49+
}
50+
raddr := &net.TCPAddr{IP: ip, Port: port}
4351
laddr := &net.TCPAddr{Port: 8080}
4452

4553
conn, err := net.DialTCP("tcp", laddr, raddr)

0 commit comments

Comments
 (0)