コード例 #1
0
func (r *RoaHttpRequestBuilder) Buid(b *BaseClient, reqObject BaseRequest) *http.Request {
	queryArgs := reqObject.GetQuery()
	bodyArgs := reqObject.GetBody()

	reqMtd := GetRequestMethod(reqObject.GetRequestMethod())

	accessUrl := getRequestUrl(b, reqObject)

	req := buildRequest(queryArgs, bodyArgs, reqMtd, accessUrl)

	addHeader(req, "Date", parameterHelper.GetRFC2616Date())
	addHeader(req, "Accept", getAcceptContentType(b.Profile.FormatType, reqMtd))
	addHeader(req, "x-acs-signature-method", b.Profile.Signer.GetSignatureMethod())
	addHeader(req, "x-acs-signature-version", b.Profile.Signer.GetVersion())
	addHeader(req, "x-acs-version", b.Version)

	if len(bodyArgs) > 0 {
		bodyUrlVals := parameterHelper.ConvertMapToUrlValues(bodyArgs)
		content := bodyUrlVals.Encode()

		contentMd5 := parameterHelper.Md5Str([]byte(content))
		req.Header.Add("Content-MD5", contentMd5)
		req.Header.Add("Content-Length", fmt.Sprintf("%d", len([]byte(content))))
		req.Header.Add("Content-Type", getAcceptContentType(b.Profile.FormatType, reqMtd))
	}

	addSdkVersion(req)
	return req
}
コード例 #2
0
func (r *OssHttpRequestBuilder) Buid(b *BaseClient, reqObject BaseRequest) *http.Request {
	queryArgs := reqObject.GetQuery()
	//commonArgs := getCommonRequestArguments(b, reqObject)
	//mergeMap(queryArgs, commonArgs)

	bodyArgs := reqObject.GetBody()

	reqMtd := GetRequestMethod(reqObject.GetRequestMethod())

	accessUrl := getRequestUrl(b, reqObject)

	req := buildRequest(queryArgs, bodyArgs, reqMtd, accessUrl)

	addHeader(req, "Date", parameterHelper.GetRFC2616Date())

	//oss only provides xml format
	//addHeader(req, "Accept", getAcceptContentType(b.Profile.FormatType, reqMtd))

	if len(bodyArgs) > 0 {
		bodyUrlVals := parameterHelper.ConvertMapToUrlValues(bodyArgs)
		content := bodyUrlVals.Encode()

		contentMd5 := parameterHelper.Md5Str([]byte(content))
		req.Header.Add("Content-MD5", contentMd5)
		req.Header.Add("Content-Length", fmt.Sprintf("%d", len([]byte(content))))
		req.Header.Add("Content-Type", getAcceptContentType(b.Profile.FormatType, reqMtd))
	}

	addSdkVersion(req)
	return req
}