MCPcopy Index your code
hub / github.com/cloudflare/cloudflared / parseURL

Function parseURL

cmd/cloudflared/access/validation.go:48–75  ·  view source on GitHub ↗

parseHostname will attempt to convert a user provided URL string into a string with some light error checking on certain expectations from the URL. Will convert all HTTP URLs to HTTPS

(input string)

Source from the content-addressed store, hash-verified

46// certain expectations from the URL.
47// Will convert all HTTP URLs to HTTPS
48func parseURL(input string) (*url.URL, error) {
49 if input == "" {
50 return nil, errors.New("no input provided")
51 }
52 if !strings.HasPrefix(input, "https://") && !strings.HasPrefix(input, "http://") {
53 input = fmt.Sprintf("https://%s", input)
54 }
55 input = bracketBareIPv6(input)
56 url, err := url.ParseRequestURI(input)
57 if err != nil {
58 return nil, fmt.Errorf("failed to parse as URL: %w", err)
59 }
60 if url.Scheme != "https" {
61 url.Scheme = "https"
62 }
63 if url.Host == "" {
64 return nil, errors.New("failed to parse Host")
65 }
66 host, err := httpguts.PunycodeHostPort(url.Host)
67 if err != nil || host == "" {
68 return nil, err
69 }
70 if !httpguts.ValidHostHeader(host) {
71 return nil, errors.New("invalid Host provided")
72 }
73 url.Host = host
74 return url, nil
75}

Callers 4

TestParseURLFunction · 0.85
getAppURLFromArgsFunction · 0.85
sshGenFunction · 0.85
sshFunction · 0.85

Calls 2

bracketBareIPv6Function · 0.85
ErrorfMethod · 0.80

Tested by 1

TestParseURLFunction · 0.68