Ejemplo n.º 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
}
Ejemplo n.º 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
}
Ejemplo n.º 3
0
func buildRequest(queryArgs, bodyArgs map[string]string, reqMtd, accessUrl string) *http.Request {
	var req *http.Request
	if reqMtd == "GET" {

		mergeMap(queryArgs, bodyArgs)

		req, _ = http.NewRequest(reqMtd, accessUrl, nil)

	} else {
		req, _ = http.NewRequest(reqMtd, accessUrl, strings.NewReader(parameterHelper.ConvertMapToUrlValues(bodyArgs).Encode()))
	}

	currQryVals := req.URL.Query()
	mergeUrlValues(currQryVals, parameterHelper.ConvertMapToUrlValues(queryArgs))
	req.URL.RawQuery = currQryVals.Encode()

	return req
}