Exemple #1
0
func (v4 *signer) buildCanonicalString() {
	v4.Request.URL.RawQuery = strings.Replace(v4.Query.Encode(), "+", "%20", -1)
	uri := v4.Request.URL.Opaque
	if uri != "" {
		uri = "/" + strings.Join(strings.Split(uri, "/")[3:], "/")
	} else {
		uri = v4.Request.URL.Path
	}
	if uri == "" {
		uri = "/"
	}

	if v4.ServiceName != "s3" {
		uri = rest.EscapePath(uri, false)
	}

	v4.canonicalString = strings.Join([]string{
		v4.Request.Method,
		uri,
		v4.Request.URL.RawQuery,
		v4.canonicalHeaders + "\n",
		v4.signedHeaders,
		v4.bodyDigest(),
	}, "\n")
}
Exemple #2
0
func (v2 *signer) buildCanonicalResource() {
	endpoint := v2.Service.Endpoint

	v2.Request.URL.RawQuery = strings.Replace(v2.Query.Encode(), "+", "%20", -1)
	url := v2.Request.URL.String()
	//在aws.service.go,buildEndpoint会把sheme也加上
	pathStyle := strings.HasPrefix(url, endpoint)
	uri := v2.Request.URL.Opaque

	bucketInHost := ""
	if !pathStyle {
		if strings.HasPrefix(url, "http://") {
			url = url[7:]
			endpoint = endpoint[7:]
		} else if strings.HasPrefix(url, "https://") {
			url = url[8:]
			endpoint = endpoint[8:]
		}
		bucketInHost = url[0 : strings.Index(url, endpoint)-1]
	}
	if uri != "" {
		uris := strings.Split(uri, "/")[3:]
		append := false
		if len(uris) == 1 && uris[0] != "" && bucketInHost == "" {
			//只有bucket
			append = true
		} else if len(uris) == 0 && bucketInHost != "" {
			append = true
		}
		uri = "/" + strings.Join(strings.Split(uri, "/")[3:], "/")
		if bucketInHost != "" {
			uri = "/" + bucketInHost + uri
		}
		if append {
			uri += "/"
		}
	} else {
		uri = v2.Request.URL.Path
	}
	if uri == "" {
		uri = "/"
	}

	if v2.ServiceName != "s3" {
		uri = rest.EscapePath(uri, false)
	}

	var querys []string
	for k := range v2.Query {
		if _, ok := signQuerys[k]; ok {
			querys = append(querys, k)
		}
	}
	sort.Strings(querys)

	queryValues := make([]string, len(querys))
	for i, k := range querys {
		v := v2.Query[k]
		vString := strings.Join(v, ",")
		if vString != "" {
			queryValues[i] = k + "=" + vString
		} else {
			queryValues[i] = k
		}
	}
	queryString := strings.Join(queryValues, "&")
	if queryString == "" {
		v2.canonicalResource = uri
	} else {
		v2.canonicalResource = uri + "?" + queryString
	}
}