Use default ports for the schemes when dialing (#7960)

Fixes #7946
This commit is contained in:
Praveen raj Mani
2019-08-13 16:43:11 +05:30
committed by Nitish Tiwari
parent aaef18b1a3
commit e96f19c867
3 changed files with 57 additions and 20 deletions

View File

@@ -19,9 +19,12 @@ package net
import (
"encoding/json"
"errors"
"net"
"net/http"
"net/url"
"path"
"strings"
"time"
)
// URL - improved JSON friendly url.URL.
@@ -79,6 +82,27 @@ func (u *URL) UnmarshalJSON(data []byte) (err error) {
return nil
}
// DialHTTP - dials the url to check the connection.
func (u URL) DialHTTP() error {
var client = &http.Client{
Transport: &http.Transport{
DialContext: (&net.Dialer{
Timeout: 2 * time.Second,
}).DialContext,
},
}
req, err := http.NewRequest("POST", u.String(), nil)
if err != nil {
return err
}
resp, err := client.Do(req)
if err != nil {
return err
}
resp.Body.Close()
return nil
}
// ParseURL - parses string into URL.
func ParseURL(s string) (u *URL, err error) {
var uu *url.URL