processURL will preprocess the string (parse to a url, convert to punycode, etc).
(s string)
| 493 | |
| 494 | // processURL will preprocess the string (parse to a url, convert to punycode, etc). |
| 495 | func processURL(s string) (*url.URL, error) { |
| 496 | u, err := url.ParseRequestURI(s) |
| 497 | if err != nil { |
| 498 | return nil, err |
| 499 | } |
| 500 | |
| 501 | if u.Host == "" { |
| 502 | return nil, errors.New("not a valid host") |
| 503 | } |
| 504 | |
| 505 | host, err := idna.ToASCII(u.Hostname()) |
| 506 | if err != nil { // we fail to convert to punycode, just return the url we parsed. |
| 507 | return u, nil |
| 508 | } |
| 509 | if u.Port() != "" { |
| 510 | u.Host = fmt.Sprintf("%s:%s", host, u.Port()) |
| 511 | } else { |
| 512 | u.Host = host |
| 513 | } |
| 514 | |
| 515 | return u, nil |
| 516 | } |
| 517 | |
| 518 | // cloudflaredPath pulls the full path of cloudflared on disk |
| 519 | func cloudflaredPath() string { |