MCPcopy Create free account
hub / github.com/google/pprof / adjustURL

Function adjustURL

internal/driver/fetch.go:595–626  ·  view source on GitHub ↗

adjustURL validates if a profile source is a URL and returns an cleaned up URL and the timeout to use for retrieval over HTTP. If the source cannot be recognized as a URL it returns an empty string.

(source string, duration, timeout time.Duration)

Source from the content-addressed store, hash-verified

593// cleaned up URL and the timeout to use for retrieval over HTTP.
594// If the source cannot be recognized as a URL it returns an empty string.
595func adjustURL(source string, duration, timeout time.Duration) (string, time.Duration) {
596 u, err := url.Parse(source)
597 if err != nil || (u.Host == "" && u.Scheme != "" && u.Scheme != "file") {
598 // Try adding http:// to catch sources of the form hostname:port/path.
599 // url.Parse treats "hostname" as the scheme.
600 u, err = url.Parse("http://" + source)
601 }
602 if err != nil || u.Host == "" {
603 return "", 0
604 }
605
606 // Apply duration/timeout overrides to URL.
607 values := u.Query()
608 if duration > 0 {
609 values.Set("seconds", fmt.Sprint(int(duration.Seconds())))
610 } else {
611 if urlSeconds := values.Get("seconds"); urlSeconds != "" {
612 if us, err := strconv.ParseInt(urlSeconds, 10, 32); err == nil {
613 duration = time.Duration(us) * time.Second
614 }
615 }
616 }
617 if timeout <= 0 {
618 if duration > 0 {
619 timeout = duration + duration/2
620 } else {
621 timeout = 60 * time.Second
622 }
623 }
624 u.RawQuery = values.Encode()
625 return u.String(), timeout
626}

Callers 1

fetchFunction · 0.85

Calls 2

ParseMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…