Esempio n. 1
0
        /// <summary>
        /// Generates a URL to access an object in a bucket
        /// </summary>
        public UrlGetResponse UrlGet(UrlGetRequest request)
        {
            UrlGetResponse response = new UrlGetResponse();

            long expires = (ThreeSharpUtils.CurrentTimeMillis() + request.ExpiresIn) / 1000;

            string canonicalString  = ThreeSharpUtils.MakeCanonicalString(request.Method, request.BucketName, request.Key, null, null, expires.ToString());
            string encodedCanonical = ThreeSharpUtils.Encode(config.AwsSecretAccessKey, canonicalString, true);

            StringBuilder builder = new StringBuilder();

            if (config.IsSecure)
            {
                builder.Append("https://");
            }
            else
            {
                builder.Append("http://");
            }
            builder.Append(ThreeSharpUtils.BuildUrlBase(config.Server, config.Port, request.BucketName, config.Format));
            if (!String.IsNullOrEmpty(request.BucketName) && !String.IsNullOrEmpty(request.Key))
            {
                builder.Append(request.Key);
            }

            request.QueryList.Add("Signature", encodedCanonical);
            request.QueryList.Add("Expires", "" + expires);
            request.QueryList.Add("AWSAccessKeyId", config.AwsAccessKeyID);
            builder.Append(ThreeSharpUtils.ConvertQueryListToQueryString(request.QueryList));

            String url = builder.ToString();

            byte[] urlBytes = (new ASCIIEncoding()).GetBytes(url);
            response.DataStream = new MemoryStream(urlBytes.Length);
            response.DataStream.Write(urlBytes, 0, urlBytes.Length);
            response.DataStream.Position = 0;

            response.BucketName   = request.BucketName;
            response.Key          = request.Key + "-URL";
            response.Method       = request.Method;
            response.TransferInfo = new TransferInfo(response);
            lock (this.statistics) { this.statistics.AddTransferInfo(response.TransferInfo); }

            return(response);
        }
Esempio n. 2
0
        /// <summary>
        /// Configures an HttpWebRequest with settings from the
        /// ThreeSharpConfig instance and the Request object instance
        /// </summary>
        private HttpWebRequest ConfigureWebRequest(Request request)
        {
            StringBuilder url = new StringBuilder();

            if (!String.IsNullOrEmpty(request.RedirectUrl))
            {
                url.Append(request.RedirectUrl);
            }
            else
            {
                url.Append(config.IsSecure ? "https://" : "http://");
                url.Append(ThreeSharpUtils.BuildUrlBase(config.Server, config.Port, request.BucketName, config.Format));

                if (!String.IsNullOrEmpty(request.Key))
                {
                    url.Append(request.Key);
                }

                // build the query string parameter
                url.Append(ThreeSharpUtils.ConvertQueryListToQueryString(request.QueryList));
            }

            HttpWebRequest httpWebRequest = WebRequest.Create(url.ToString()) as HttpWebRequest;

            httpWebRequest.AllowWriteStreamBuffering = false;
            httpWebRequest.AllowAutoRedirect         = false;
            httpWebRequest.UserAgent     = config.UserAgent;
            httpWebRequest.Method        = request.Method;
            httpWebRequest.Timeout       = request.Timeout;
            httpWebRequest.ContentType   = request.ContentType;
            httpWebRequest.ContentLength = request.BytesTotal;
            if (this.config.Proxy != null)
            {
                httpWebRequest.Proxy = this.config.Proxy;
            }

            AddHeaders(httpWebRequest, request.Headers);
            AddMetadataHeaders(httpWebRequest, request.MetaData);
            AddAuthorizationHeader(httpWebRequest, request.BucketName, request.Key, request.QueryList);

            return(httpWebRequest);
        }
Esempio n. 3
0
        /// <summary>
        /// Configures an HttpWebRequest with settings from the
        /// ThreeSharpConfig instance and the Request object instance
        /// </summary>
        private HttpWebRequest ConfigureWebRequest(Request request)
        {
            HttpWebRequest httpWebRequest = null;

            if (request.ServiceType == ThreeSharpServiceType.S3)
            {
                S3Request     s3Request = (S3Request)request;
                StringBuilder url       = new StringBuilder();
                String        finalUrl  = string.Empty;

                if (!String.IsNullOrEmpty(s3Request.RedirectUrl))
                {
                    url.Append(s3Request.RedirectUrl);
                }
                else
                {
                    if (s3Request.QueryList.ContainsKey("requestPayment"))
                    {
                        config.Format = CallingFormat.SUBDOMAIN;
                    }

                    url.Append(config.IsSecure ? "https://" : "http://");
                    url.Append(ThreeSharpUtils.BuildUrlBase(config.Server, config.Port, s3Request.BucketName, config.Format));

                    if (!String.IsNullOrEmpty(s3Request.Key))
                    {
                        url.Append(s3Request.Key);
                    }

                    // build the query string parameter
                    url.Append(ThreeSharpUtils.ConvertQueryListToQueryString(s3Request.QueryList));
                }

                httpWebRequest = WebRequest.Create(url.ToString()) as HttpWebRequest;
                httpWebRequest.AllowWriteStreamBuffering = false;
                httpWebRequest.AllowAutoRedirect         = false;
                httpWebRequest.UserAgent     = config.UserAgent;
                httpWebRequest.Method        = s3Request.Method;
                httpWebRequest.Timeout       = s3Request.Timeout;
                httpWebRequest.ContentType   = s3Request.ContentType;
                httpWebRequest.ContentLength = s3Request.BytesTotal;

                if (this.config.Proxy != null)
                {
                    httpWebRequest.Proxy = this.config.Proxy;
                }

                this.AddHeaders(httpWebRequest, s3Request.Headers);
                this.AddMetadataHeaders(httpWebRequest, s3Request.MetaData);
                this.AddAuthorizationHeader(httpWebRequest, s3Request);
            }
            else
            {
                AWS100Request aws100Request = (AWS100Request)request;
                StringBuilder url           = new StringBuilder();

                url.Append("https://");
                url.Append(config.Server);
                url.Append(":");
                url.Append("443");
                url.Append("/2008-06-30/distribution/");
                if (!string.IsNullOrEmpty(aws100Request.DistributionID))
                {
                    url.Append(aws100Request.DistributionID);
                    if (aws100Request.GetType() == typeof(DistributionUpdateRequest))
                    {
                        url.Append("/config");
                    }
                }

                httpWebRequest           = WebRequest.Create(url.ToString()) as HttpWebRequest;
                httpWebRequest.KeepAlive = true;
                httpWebRequest.AllowWriteStreamBuffering = false;
                httpWebRequest.AllowAutoRedirect         = false;
                httpWebRequest.UserAgent     = config.UserAgent;
                httpWebRequest.Method        = aws100Request.Method;
                httpWebRequest.Timeout       = aws100Request.Timeout;
                httpWebRequest.ContentType   = aws100Request.ContentType;
                httpWebRequest.ContentLength = aws100Request.BytesTotal;

                if (this.config.Proxy != null)
                {
                    httpWebRequest.Proxy = this.config.Proxy;
                }

                this.AddHeaders(httpWebRequest, aws100Request.Headers);
                this.AddMetadataHeaders(httpWebRequest, aws100Request.MetaData);
                this.AddAuthorizationHeader(httpWebRequest, aws100Request);
            }

            return(httpWebRequest);
        }