Exemple #1
0
        private bool CheckHasSign(CosRequest cosRequest)
        {
            if (cosRequest.GetRequestHeaders().ContainsKey(CosRequestHeaderKey.AUTHORIZAIION))
            {
                return(true);
            }

            return(false);
        }
        private Request CreateRequest(CosRequest cosRequest)
        {
            cosRequest.CheckParameters();
            string  requestUrlWithSign = cosRequest.RequestURLWithSign;
            Request request            = new Request();

            request.Method = cosRequest.Method;
            if (requestUrlWithSign != null)
            {
                if (requestUrlWithSign.StartsWith("https"))
                {
                    request.IsHttps = true;
                }
                else
                {
                    request.IsHttps = false;
                }
                request.RequestUrlString = requestUrlWithSign;
            }
            else
            {
                request.IsHttps = (bool)cosRequest.IsHttps;
                request.Url     = CreateUrl(cosRequest);
                request.Host    = cosRequest.GetHost();
            }
            request.UserAgent = config.UserAgnet;
            Dictionary <string, string> headers = cosRequest.GetRequestHeaders();

            if (headers != null)
            {
                foreach (KeyValuePair <string, string> pair in headers)
                {
                    request.AddHeader(pair.Key, pair.Value);
                }
            }
            request.Body = cosRequest.GetRequestBody();

            // cacluate md5
            if (CheckNeedMd5(request, cosRequest.IsNeedMD5) && request.Body != null)
            {
                request.AddHeader(CosRequestHeaderKey.CONTENT_MD5, request.Body.GetMD5());
            }
            // content type header
            if (request.Body != null && request.Body.ContentType != null &&
                !request.Headers.ContainsKey(CosRequestHeaderKey.CONTENT_TYPE))
            {
                request.AddHeader(CosRequestHeaderKey.CONTENT_TYPE, request.Body.ContentType);
            }

            //cacluate sign, and add it.
            if (requestUrlWithSign == null)
            {
                CheckSign(cosRequest.GetSignSourceProvider(), request);
            }
            return(request);
        }
Exemple #3
0
        private Request CreateRequest(CosRequest cosRequest)
        {
            Request request = new Request();

            request.Method  = cosRequest.Method;
            request.IsHttps = cosRequest.IsHttps;
            request.SetHttpUrl(CreateUrl(cosRequest));
            Dictionary <string, string> headers = cosRequest.GetRequestHeaders();

            if (headers != null)
            {
                foreach (KeyValuePair <string, string> pair in headers)
                {
                    request.AddHeader(pair.Key, pair.Value);
                }
            }

            request.Body = cosRequest.GetRequestBody();
            return(request);
        }