mirror of
https://github.com/minio/mc.git
synced 2025-11-13 12:22:45 +03:00
Adding more iodine to url parser
This commit is contained in:
@@ -39,7 +39,7 @@ const (
|
|||||||
func getURLType(urlStr string) (uType urlType, err error) {
|
func getURLType(urlStr string) (uType urlType, err error) {
|
||||||
u, err := url.Parse(urlStr)
|
u, err := url.Parse(urlStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return urlUnknown, err
|
return urlUnknown, iodine.New(err, nil)
|
||||||
}
|
}
|
||||||
switch u.Scheme {
|
switch u.Scheme {
|
||||||
case "http":
|
case "http":
|
||||||
@@ -78,23 +78,23 @@ func isValidFileURL(urlStr string) bool {
|
|||||||
// fixFileURL rewrites file URL to proper file:///path/to/ form.
|
// fixFileURL rewrites file URL to proper file:///path/to/ form.
|
||||||
func fixFileURL(urlStr string) (fixedURL string, err error) {
|
func fixFileURL(urlStr string) (fixedURL string, err error) {
|
||||||
if urlStr == "" {
|
if urlStr == "" {
|
||||||
return "", errEmptyURL
|
return "", iodine.New(errEmptyURL, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
utype, e := getURLType(urlStr)
|
utype, e := getURLType(urlStr)
|
||||||
if e != nil || utype != urlFile {
|
if e != nil || utype != urlFile {
|
||||||
return "", e
|
return "", iodine.New(e, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
u, e := url.Parse(urlStr)
|
u, e := url.Parse(urlStr)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return "", e
|
return "", iodine.New(e, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// file:///path should always have empty host
|
// file:///path should always have empty host
|
||||||
if u.Host != "" {
|
if u.Host != "" {
|
||||||
// Not really a file URL. Host is not empty.
|
// Not really a file URL. Host is not empty.
|
||||||
return "", errInvalidURL
|
return "", iodine.New(errInvalidURL, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill missing scheme
|
// fill missing scheme
|
||||||
@@ -111,17 +111,17 @@ func fixFileURL(urlStr string) (fixedURL string, err error) {
|
|||||||
// url2Host extracts hostname from the URL.
|
// url2Host extracts hostname from the URL.
|
||||||
func url2Host(urlStr string) (host string, err error) {
|
func url2Host(urlStr string) (host string, err error) {
|
||||||
if urlStr == "" {
|
if urlStr == "" {
|
||||||
return "", errEmptyURL
|
return "", iodine.New(errEmptyURL, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
utype, e := getURLType(urlStr)
|
utype, e := getURLType(urlStr)
|
||||||
if e != nil || utype != urlFile {
|
if e != nil || utype != urlFile {
|
||||||
return "", e
|
return "", iodine.New(e, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
u, e := url.Parse(urlStr)
|
u, e := url.Parse(urlStr)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return "", e
|
return "", iodine.New(e, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
return u.Host, nil
|
return u.Host, nil
|
||||||
@@ -132,7 +132,7 @@ func url2Object(urlStr string) (bucketName, objectName string, err error) {
|
|||||||
u, err := url.Parse(urlStr)
|
u, err := url.Parse(urlStr)
|
||||||
if u.Path == "" {
|
if u.Path == "" {
|
||||||
// No bucket name passed. It is a valid case
|
// No bucket name passed. It is a valid case
|
||||||
return "", "", nil
|
return "", "", iodine.New(errInvalidbucket, nil)
|
||||||
}
|
}
|
||||||
splits := strings.SplitN(u.Path, "/", 3)
|
splits := strings.SplitN(u.Path, "/", 3)
|
||||||
switch len(splits) {
|
switch len(splits) {
|
||||||
|
|||||||
Reference in New Issue
Block a user