func cleanPath(u *url.URL) { hasSlash := strings.HasSuffix(u.Path, "/") // clean up path, removing duplicate `/` u.Path = path.Clean(u.Path) u.RawPath = path.Clean(u.RawPath) if hasSlash && !strings.HasSuffix(u.Path, "/") { u.Path += "/" u.RawPath += "/" } }
// Expand subsitutes any {encoded} strings in the URL passed in using // the map supplied. // // This calls SetOpaque to avoid encoding of the parameters in the URL path. func Expand(u *url.URL, expansions map[string]string) { escaped, unescaped, err := uritemplates.Expand(u.Path, expansions) if err == nil { u.Path = unescaped u.RawPath = escaped } }
func buildURI(u *url.URL, v reflect.Value, name string) error { value, err := convertType(v) if err == errValueNotSet { return nil } else if err != nil { return awserr.New("SerializationError", "failed to encode REST request", err) } u.Path = strings.Replace(u.Path, "{"+name+"}", value, -1) u.Path = strings.Replace(u.Path, "{"+name+"+}", value, -1) u.RawPath = strings.Replace(u.RawPath, "{"+name+"}", EscapePath(value, true), -1) u.RawPath = strings.Replace(u.RawPath, "{"+name+"+}", EscapePath(value, false), -1) return nil }
func newResetLevelsEndpoint(URL url.URL, path string) endpoint.Endpoint { URL.Path = path URL.RawPath = path newEndpoint := httptransport.NewClient( "POST", &URL, resetLevelsEncoder, resetLevelsDecoder, ).Endpoint() return newEndpoint }
func newSetVerbosityEndpoint(URL url.URL, path string) endpoint.Endpoint { URL.Path = path URL.RawPath = path newEndpoint := httptransport.NewClient( "POST", &URL, setVerbosityEncoder, setVerbosityDecoder, ).Endpoint() return newEndpoint }
func Normalize(u *url.URL) error { if !utf8.ValidString(u.String()) { return fmt.Errorf("normalize URL: invalid UTF-8 string: %q", u.String()) } u.Scheme = strings.ToLower(u.Scheme) if u.Scheme != "http" && u.Scheme != "https" { return fmt.Errorf("normalize URL: unsupported scheme: %v", u.Scheme) } host, port, err := net.SplitHostPort(u.Host) if err != nil { // missing port host, port = u.Host, "" } if host == "" { return errors.New("normalize URL: empty host") } else if v, err := validateHost(host); err != nil { return fmt.Errorf("normalize URL: invalid host %q: %v", host, err) } else { u.Host = v } if (u.Scheme == "http" && port == "80") || (u.Scheme == "https" && port == "443") { port = "" } if port != "" { u.Host = net.JoinHostPort(u.Host, port) } clean := func(pth string) string { p := path.Clean(pth) if p == "." { p = "" } else if strings.HasSuffix(pth, "/") && !strings.HasSuffix(p, "/") { p += "/" } return p } u.Path = clean(u.Path) u.RawPath = clean(u.RawPath) u.Fragment = "" return nil }