internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
    {
        // ``us-east-1`` is not a valid location constraint according to amazon, so we skip it.
        if (!string.IsNullOrEmpty(Location) && Location != "us-east-1")
        {
            var config = new CreateBucketConfiguration(Location);
            var body   = utils.MarshalXML(config, "http://s3.amazonaws.com/doc/2006-03-01/");
            requestMessageBuilder.AddXmlBody(body);
            requestMessageBuilder.AddOrUpdateHeaderParameter("Content-Md5",
                                                             utils.getMD5SumStr(Encoding.UTF8.GetBytes(body)));
        }

        if (ObjectLock)
        {
            requestMessageBuilder.AddOrUpdateHeaderParameter("X-Amz-Bucket-Object-Lock-Enabled", "true");
        }
        return(requestMessageBuilder);
    }
    internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
    {
        requestMessageBuilder.AddQueryParameter("object-lock", "");
        var body = utils.MarshalXML(new ObjectLockConfiguration(), "http://s3.amazonaws.com/doc/2006-03-01/");

        requestMessageBuilder.AddXmlBody(body);
        requestMessageBuilder.AddOrUpdateHeaderParameter("Content-Md5",
                                                         utils.getMD5SumStr(Encoding.UTF8.GetBytes(body)));
        return(requestMessageBuilder);
    }
    internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
    {
        requestMessageBuilder.AddQueryParameter("tagging", "");
        var body = BucketTags.MarshalXML();

        requestMessageBuilder.AddXmlBody(body);
        requestMessageBuilder.AddOrUpdateHeaderParameter("Content-Md5",
                                                         utils.getMD5SumStr(Encoding.UTF8.GetBytes(body)));

        //
        return(requestMessageBuilder);
    }
Ejemplo n.º 4
0
 internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
 {
     if (!string.IsNullOrEmpty(MatchETag))
     {
         requestMessageBuilder.AddOrUpdateHeaderParameter("If-Match", MatchETag);
     }
     if (!string.IsNullOrEmpty(NotMatchETag))
     {
         requestMessageBuilder.AddOrUpdateHeaderParameter("If-None-Match", NotMatchETag);
     }
     if (ModifiedSince != default)
     {
         requestMessageBuilder.AddOrUpdateHeaderParameter("If-Modified-Since", utils.To8601String(ModifiedSince));
     }
     if (UnModifiedSince != default)
     {
         requestMessageBuilder.AddOrUpdateHeaderParameter("If-Unmodified-Since",
                                                          utils.To8601String(UnModifiedSince));
     }
     return(requestMessageBuilder);
 }
    internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
    {
        var config = new VersioningConfiguration(CurrentVersioningStatus == VersioningStatus.Enabled);

        var body = utils.MarshalXML(config, "http://s3.amazonaws.com/doc/2006-03-01/");

        requestMessageBuilder.AddXmlBody(body);
        requestMessageBuilder.AddOrUpdateHeaderParameter("Content-Md5",
                                                         utils.getMD5SumStr(Encoding.UTF8.GetBytes(body)));

        requestMessageBuilder.AddQueryParameter("versioning", "");
        return(requestMessageBuilder);
    }
    internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
    {
        requestMessageBuilder.AddQueryParameter("lifecycle", "");
        var body = BucketLifecycle.MarshalXML();
        // Convert string to a byte array
        var bodyInBytes = Encoding.ASCII.GetBytes(body);

        requestMessageBuilder.BodyParameters.Add("content-type", "text/xml");
        requestMessageBuilder.SetBody(bodyInBytes);
        requestMessageBuilder.AddOrUpdateHeaderParameter("Content-Md5",
                                                         utils.getMD5SumStr(bodyInBytes));

        return(requestMessageBuilder);
    }
Ejemplo n.º 7
0
    private async Task <ResponseResult> ExecuteTaskCoreAsync(
        IEnumerable <ApiResponseErrorHandlingDelegate> errorHandlers,
        HttpRequestMessageBuilder requestMessageBuilder,
        CancellationToken cancellationToken = default,
        bool isSts = false)
    {
        var startTime = DateTime.Now;

        // Logs full url when HTTPtracing is enabled.
        if (trace)
        {
            var fullUrl = requestMessageBuilder.RequestUri;
        }

        var v4Authenticator = new V4Authenticator(Secure,
                                                  AccessKey, SecretKey, Region,
                                                  SessionToken);

        requestMessageBuilder.AddOrUpdateHeaderParameter("Authorization",
                                                         v4Authenticator.Authenticate(requestMessageBuilder, isSts));

        var request = requestMessageBuilder.Request;

        ResponseResult responseResult;

        try
        {
            var response = await HTTPClient.SendAsync(request,
                                                      HttpCompletionOption.ResponseHeadersRead, cancellationToken)
                           .ConfigureAwait(false);

            responseResult = new ResponseResult(request, response);
            if (requestMessageBuilder.ResponseWriter != null)
            {
                requestMessageBuilder.ResponseWriter(responseResult.ContentStream);
            }
        }
        catch (OperationCanceledException)
        {
            throw;
        }
        catch (Exception e)
        {
            responseResult = new ResponseResult(request, e);
        }

        HandleIfErrorResponse(responseResult, errorHandlers, startTime);
        return(responseResult);
    }
    internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuilder requestMessageBuilder)
    {
        requestMessageBuilder.AddQueryParameter("object-lock", "");
        var body = utils.MarshalXML(LockConfiguration, "http://s3.amazonaws.com/doc/2006-03-01/");

        // Convert string to a byte array
        // byte[] bodyInBytes = Encoding.ASCII.GetBytes(body);

        // requestMessageBuilder.BodyParameters.Add("content-type", "text/xml");
        // requestMessageBuilder.SetBody(bodyInBytes);
        //
        // string body = utils.MarshalXML(config, "http://s3.amazonaws.com/doc/2006-03-01/");
        requestMessageBuilder.AddXmlBody(body);
        requestMessageBuilder.AddOrUpdateHeaderParameter("Content-Md5",
                                                         utils.getMD5SumStr(Encoding.UTF8.GetBytes(body)));
        //
        return(requestMessageBuilder);
    }