MCPcopy Create free account
hub / github.com/cloudflare/cfssl / normalizeURL

Function normalizeURL

api/client/client.go:333–371  ·  view source on GitHub ↗

normalizeURL checks for http/https protocol, appends "http" as default protocol if not defined in url

(addr string)

Source from the content-addressed store, hash-verified

331
332// normalizeURL checks for http/https protocol, appends "http" as default protocol if not defined in url
333func normalizeURL(addr string) (*url.URL, error) {
334 addr = strings.TrimSpace(addr)
335
336 u, err := url.Parse(addr)
337 if err != nil {
338 return nil, err
339 }
340
341 if u.Opaque != "" {
342 u.Host = net.JoinHostPort(u.Scheme, u.Opaque)
343 u.Opaque = ""
344 } else if u.Path != "" && !strings.Contains(u.Path, ":") {
345 u.Host = net.JoinHostPort(u.Path, "8888")
346 u.Path = ""
347 } else if u.Scheme == "" {
348 u.Host = u.Path
349 u.Path = ""
350 }
351
352 if u.Scheme != "https" {
353 u.Scheme = "http"
354 }
355
356 _, port, err := net.SplitHostPort(u.Host)
357 if err != nil {
358 _, port, err = net.SplitHostPort(u.Host + ":8888")
359 if err != nil {
360 return nil, err
361 }
362 }
363
364 if port != "" {
365 _, err = strconv.Atoi(port)
366 if err != nil {
367 return nil, err
368 }
369 }
370 return u, nil
371}

Callers 2

NewGroupFunction · 0.85
NewServerTLSFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…