コード例 #1
0
        private static bool HasSSEHeaders(IWebResponseData webResponseData)
        {
            bool usesCustomerAlgorithm = !string.IsNullOrEmpty(webResponseData.GetHeaderValue(HeaderKeys.XAmzSSECustomerAlgorithmHeader));
            bool usesKmsKeyId          = !string.IsNullOrEmpty(webResponseData.GetHeaderValue(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader));

            return(usesCustomerAlgorithm || usesKmsKeyId);
        }
コード例 #2
0
        private static bool HasSSEHeaders(IWebResponseData webResponseData)
        {
            bool num  = !string.IsNullOrEmpty(webResponseData.GetHeaderValue("x-amz-server-side-encryption-customer-algorithm"));
            bool flag = !string.IsNullOrEmpty(webResponseData.GetHeaderValue("x-amz-server-side-encryption-aws-kms-key-id"));

            return(num | flag);
        }
コード例 #3
0
        private void PostResponseHelper(IAsyncResult result)
        {
            IAsyncExecutionContext executionContext = result.AsyncState as IAsyncExecutionContext;
            IWebResponseData       response         = executionContext.ResponseContext.HttpResponse;
            RuntimeAsyncResult     asyncResult      = executionContext.ResponseContext.AsyncResult as RuntimeAsyncResult;

            if (executionContext.ResponseContext.AsyncResult.Exception == null)
            {
                PostObjectResponse postResponse = new PostObjectResponse();
                postResponse.HttpStatusCode = response.StatusCode;
                postResponse.ContentLength  = response.ContentLength;

                if (response.IsHeaderPresent(HeaderKeys.XAmzRequestIdHeader))
                {
                    postResponse.RequestId = response.GetHeaderValue(HeaderKeys.XAmzRequestIdHeader);
                }
                if (response.IsHeaderPresent(HeaderKeys.XAmzId2Header))
                {
                    postResponse.HostId = response.GetHeaderValue(HeaderKeys.XAmzId2Header);
                }
                if (response.IsHeaderPresent(HeaderKeys.XAmzVersionIdHeader))
                {
                    postResponse.VersionId = response.GetHeaderValue(HeaderKeys.XAmzVersionIdHeader);
                }

                PostObjectRequest request = executionContext.RequestContext.OriginalRequest as PostObjectRequest;
                asyncResult.Request  = request;
                asyncResult.Response = postResponse;
            }

            asyncResult.Exception = executionContext.ResponseContext.AsyncResult.Exception;
            asyncResult.Action    = executionContext.RequestContext.Action;
            asyncResult.InvokeCallback();
        }
コード例 #4
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, PutObjectResponse response)
        {
            IWebResponseData responseData = context.ResponseData;

            if (responseData.IsHeaderPresent("x-amz-expiration"))
            {
                response.Expiration = new Expiration(responseData.GetHeaderValue("x-amz-expiration"));
            }
            if (responseData.IsHeaderPresent("x-amz-server-side-encryption"))
            {
                response.ServerSideEncryptionMethod = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-server-side-encryption"));
            }
            if (responseData.IsHeaderPresent("ETag"))
            {
                response.ETag = S3Transforms.ToString(responseData.GetHeaderValue("ETag"));
            }
            if (responseData.IsHeaderPresent("x-amz-version-id"))
            {
                response.VersionId = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-version-id"));
            }
            if (responseData.IsHeaderPresent(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader))
            {
                response.ServerSideEncryptionKeyManagementServiceKeyId = S3Transforms.ToString(responseData.GetHeaderValue(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader));
            }
            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderRequestCharged))
            {
                response.RequestCharged = RequestCharged.FindValue(responseData.GetHeaderValue(S3Constants.AmzHeaderRequestCharged));
            }

            return;
        }
コード例 #5
0
        /// <summary>
        /// Wrap the jsonstring for unmarshalling.
        /// </summary>
        /// <param name="responseStream">Stream that contains the JSON for unmarshalling</param>
        /// <param name="maintainResponseBody"> If set to true, maintains a copy of the complete response body constraint to log response size as the stream is being read.</param>
        /// <param name="responseData">Response data coming back from the request</param>
        /// <param name="isException">If set to true, maintains a copy of the complete response body as the stream is being read.</param>
        /// <param name="requestContext">Context for the request that produced this response</param>
        public JsonUnmarshallerContext(
            Stream responseStream,
            bool maintainResponseBody,
            IWebResponseData responseData,
            bool isException,
            IRequestContext requestContext)
        {
            if (isException)
            {
                this.WrappingStream = new CachingWrapperStream(responseStream);
            }
            else if (maintainResponseBody)
            {
                this.WrappingStream = new CachingWrapperStream(responseStream, AWSConfigs.LoggingConfig.LogResponsesSizeLimit);
            }

            if (isException || maintainResponseBody)
            {
                responseStream = this.WrappingStream;
            }

            this.WebResponseData      = responseData;
            this.MaintainResponseBody = maintainResponseBody;
            this.IsException          = isException;

            //if the json unmarshaller context is being called internally without there being a http response then the response data would be null
            if (responseData != null)
            {
                long contentLength;

                bool parsedContentLengthHeader = long.TryParse(responseData.GetHeaderValue("Content-Length"), out contentLength);

                // Temporary work around checking Content-Encoding for an issue with NetStandard on Linux returning Content-Length for a gzipped response.
                // Causing the SDK to attempt a CRC check over the gzipped response data with a CRC value for the uncompressed value.
                // The Content-Encoding check can be removed with the following github issue is shipped.
                // https://github.com/dotnet/corefx/issues/6796

                if (parsedContentLengthHeader && responseData.ContentLength.Equals(contentLength) &&
                    string.IsNullOrEmpty(responseData.GetHeaderValue("Content-Encoding")))
                {
                    base.SetupCRCStream(responseData, responseStream, contentLength);
                    base.SetupFlexibleChecksumStream(responseData, CrcStream ?? responseStream, contentLength, requestContext);
                }
            }

            if (this.FlexibleChecksumStream != null) // either just flexible checksum, or flexible checksum wrapping the older CRC stream
            {
                streamReader = new StreamReader(this.FlexibleChecksumStream);
            }
            else if (this.CrcStream != null)
            {
                streamReader = new StreamReader(this.CrcStream);
            }
            else
            {
                streamReader = new StreamReader(responseStream);
            }

            jsonReader = new JsonReader(streamReader);
        }
        private static void UnmarshallResult(XmlUnmarshallerContext context, PutObjectResponseECS response)
        {
            IWebResponseData responseData = context.ResponseData;

            if (responseData.IsHeaderPresent("x-amz-expiration"))
            {
                response.Expiration = ParseExpirationHeader(responseData.GetHeaderValue("x-amz-expiration"));
            }
            if (responseData.IsHeaderPresent("x-amz-server-side-encryption"))
            {
                response.ServerSideEncryptionMethod = ECSTransforms.ToString(responseData.GetHeaderValue("x-amz-server-side-encryption"));
            }
            if (responseData.IsHeaderPresent("ETag"))
            {
                response.ETag = ECSTransforms.ToString(responseData.GetHeaderValue("ETag"));
            }
            if (responseData.IsHeaderPresent("x-amz-version-id"))
            {
                response.VersionId = ECSTransforms.ToString(responseData.GetHeaderValue("x-amz-version-id"));
            }
            if (responseData.IsHeaderPresent(COMMON.XAmzServerSideEncryptionAwsKmsKeyIdHeader))
            {
                response.ServerSideEncryptionKeyManagementServiceKeyId = ECSTransforms.ToString(responseData.GetHeaderValue(COMMON.XAmzServerSideEncryptionAwsKmsKeyIdHeader));
            }
            if (responseData.IsHeaderPresent(COMMON.EMC_APPEND_OFFSET))
            {
                response.AppendOffset = Convert.ToInt64(ECSTransforms.ToString(responseData.GetHeaderValue(COMMON.EMC_APPEND_OFFSET)));
            }

            return;
        }
コード例 #7
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, CopyObjectResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            if (context.IsStartOfDocument)
            {
                targetDepth += 2;
            }

            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("ETag", targetDepth))
                    {
                        response.ETag = StringUnmarshaller.GetInstance().Unmarshall(context);

                        continue;
                    }
                    if (context.TestExpression("LastModified", targetDepth))
                    {
                        response.LastModified = StringUnmarshaller.GetInstance().Unmarshall(context);

                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    return;
                }
            }


            IWebResponseData responseData = context.ResponseData;

            if (responseData.IsHeaderPresent("x-amz-expiration"))
            {
                response.Expiration = new Expiration(responseData.GetHeaderValue("x-amz-expiration"));
            }
            if (responseData.IsHeaderPresent("x-amz-copy-source-version-id"))
            {
                response.SourceVersionId = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-copy-source-version-id"));
            }
            if (responseData.IsHeaderPresent("x-amz-server-side-encryption"))
            {
                response.ServerSideEncryptionMethod = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-server-side-encryption"));
            }
            if (responseData.IsHeaderPresent(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader))
            {
                response.ServerSideEncryptionKeyManagementServiceKeyId = S3Transforms.ToString(responseData.GetHeaderValue(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader));
            }
            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderRequestCharged))
            {
                response.RequestCharged = RequestCharged.FindValue(responseData.GetHeaderValue(S3Constants.AmzHeaderRequestCharged));
            }

            return;
        }
コード例 #8
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, CompleteMultipartUploadResponse response)
        {
            int currentDepth = context.get_CurrentDepth();
            int num          = currentDepth + 1;

            if (context.get_IsStartOfDocument())
            {
                num += 2;
            }
            while (context.Read())
            {
                if (context.get_IsStartElement() || context.get_IsAttribute())
                {
                    if (context.TestExpression("Location", num))
                    {
                        response.Location = StringUnmarshaller.GetInstance().Unmarshall(context);
                    }
                    else if (context.TestExpression("Bucket", num))
                    {
                        response.BucketName = StringUnmarshaller.GetInstance().Unmarshall(context);
                    }
                    else if (context.TestExpression("Key", num))
                    {
                        response.Key = StringUnmarshaller.GetInstance().Unmarshall(context);
                    }
                    else if (context.TestExpression("ETag", num))
                    {
                        response.ETag = StringUnmarshaller.GetInstance().Unmarshall(context);
                    }
                }
                else if (context.get_IsEndElement() && context.get_CurrentDepth() < currentDepth)
                {
                    return;
                }
            }
            IWebResponseData responseData = context.get_ResponseData();

            if (responseData.IsHeaderPresent("x-amz-expiration"))
            {
                response.Expiration = new Expiration(responseData.GetHeaderValue("x-amz-expiration"));
            }
            if (responseData.IsHeaderPresent("x-amz-server-side-encryption"))
            {
                response.ServerSideEncryptionMethod = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-server-side-encryption"));
            }
            if (responseData.IsHeaderPresent("x-amz-version-id"))
            {
                response.VersionId = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-version-id"));
            }
            if (responseData.IsHeaderPresent("x-amz-server-side-encryption-aws-kms-key-id"))
            {
                response.ServerSideEncryptionKeyManagementServiceKeyId = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-server-side-encryption-aws-kms-key-id"));
            }
            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderRequestCharged))
            {
                response.RequestCharged = RequestCharged.FindValue(responseData.GetHeaderValue(S3Constants.AmzHeaderRequestCharged));
            }
        }
コード例 #9
0
        /// <summary>
        /// Wrap the jsonstring for unmarshalling.
        /// </summary>
        /// <param name="responseStream">Stream that contains the JSON for unmarshalling</param>
        /// <param name="maintainResponseBody"> If set to true, maintains a copy of the complete response body constraint to log response size as the stream is being read.</param>
        /// <param name="responseData">Response data coming back from the request</param>
        /// <param name="isException">If set to true, maintains a copy of the complete response body as the stream is being read.</param>
        public JsonUnmarshallerContext(Stream responseStream, bool maintainResponseBody, IWebResponseData responseData, bool isException = false)
        {
            if (isException)
            {
                this.WrappingStream = new CachingWrapperStream(responseStream);
            }
            else if (maintainResponseBody)
            {
                this.WrappingStream = new CachingWrapperStream(responseStream, AWSConfigs.LoggingConfig.LogResponsesSizeLimit);
            }

            if (isException || maintainResponseBody)
            {
                responseStream = this.WrappingStream;
            }

            this.WebResponseData      = responseData;
            this.MaintainResponseBody = maintainResponseBody;
            this.IsException          = isException;


            //if the json unmarshaller context is being called internally without their being a http response then the response data would be null
            if (responseData != null)
            {
                long contentLength;

                bool parsedContentLengthHeader = long.TryParse(responseData.GetHeaderValue("Content-Length"), out contentLength);

                //possible scenario in unity where the content length in header does not match responseData.ContentLength
                //responseData.ContentLength represents actual bytes downloaded header value represents the length sent from the server.
                //we will only try to setup crc32 in case the responseData.ContentLength is same as the content length from the header.
                //failing to do so may result in the stream being cut off in the middle (since the zip stream length is less than the responseData.ContentLength)
                //or may result in a crc32 exception since the crc32 calcuated value for an unzipped stream will differ from the crc32 values for a zipped stream.
                //
                // Temporary work around checking Content-Encoding for an issue with NetStandard on Linux returning Content-Length for a gzipped response.
                // Causing the SDK to attempt a CRC check over the gzipped response data with a CRC value for the uncompressed value.
                // The Content-Encoding check can be removed with the following github issue is shipped.
                // https://github.com/dotnet/corefx/issues/6796

                if (parsedContentLengthHeader && responseData.ContentLength.Equals(contentLength) &&
                    string.IsNullOrEmpty(responseData.GetHeaderValue("Content-Encoding")))
                {
                    base.SetupCRCStream(responseData, responseStream, contentLength);
                }
            }

            if (this.CrcStream != null)
            {
                streamReader = new StreamReader(this.CrcStream);
            }
            else
            {
                streamReader = new StreamReader(responseStream);
            }

            jsonReader = new JsonReader(streamReader);
        }
コード例 #10
0
        public override UnmarshallerContext CreateContext(IWebResponseData response, bool readEntireResponse, Stream stream, RequestMetrics metrics)
        {
            if (response.IsHeaderPresent(HeaderKeys.XAmzId2Header))
                metrics.AddProperty(Metric.AmzId2, response.GetHeaderValue(HeaderKeys.XAmzId2Header));

            if (response.IsHeaderPresent(HeaderKeys.XAmzCloudFrontIdHeader))
                metrics.AddProperty(Metric.AmzCfId, response.GetHeaderValue(HeaderKeys.XAmzCloudFrontIdHeader));

            return base.CreateContext(response, readEntireResponse, stream, metrics);
        }
コード例 #11
0
 public override UnmarshallerContext CreateContext(IWebResponseData response, bool readEntireResponse, Stream stream, RequestMetrics metrics)
 {
     if (response.IsHeaderPresent("x-amz-id-2"))
     {
         metrics.AddProperty(2, (object)response.GetHeaderValue("x-amz-id-2"));
     }
     if (response.IsHeaderPresent("X-Amz-Cf-Id"))
     {
         metrics.AddProperty(25, (object)response.GetHeaderValue("X-Amz-Cf-Id"));
     }
     return(this.CreateContext(response, readEntireResponse, stream, metrics));
 }
コード例 #12
0
        public PostObjectResponse(IWebResponseData response)
        {
            HttpStatusCode = response.StatusCode;
            ContentLength = response.ContentLength;

            if (response.IsHeaderPresent(HeaderKeys.XAmzRequestIdHeader))
                RequestId = response.GetHeaderValue(HeaderKeys.XAmzRequestIdHeader);
            if (response.IsHeaderPresent(HeaderKeys.XAmzId2Header))
                HostId = response.GetHeaderValue(HeaderKeys.XAmzId2Header);
            if (response.IsHeaderPresent(HeaderKeys.XAmzVersionId))
                VersionId = response.GetHeaderValue(HeaderKeys.XAmzVersionId);
        }
コード例 #13
0
        public override UnmarshallerContext CreateContext(IWebResponseData response, bool readEntireResponse, Stream stream, RequestMetrics metrics)
        {
            if (response.IsHeaderPresent(HeaderKeys.XAmzId2Header))
            {
                metrics.AddProperty(Metric.AmzId2, response.GetHeaderValue(HeaderKeys.XAmzId2Header));
            }

            if (response.IsHeaderPresent(HeaderKeys.XAmzCloudFrontIdHeader))
            {
                metrics.AddProperty(Metric.AmzCfId, response.GetHeaderValue(HeaderKeys.XAmzCloudFrontIdHeader));
            }

            return(base.CreateContext(response, readEntireResponse, stream, metrics));
        }
コード例 #14
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, CopyPartResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            if (context.IsStartOfDocument)
            {
                targetDepth += 2;
            }

            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("ETag", targetDepth))
                    {
                        response.ETag = StringUnmarshaller.GetInstance().Unmarshall(context);

                        continue;
                    }
                    if (context.TestExpression("LastModified", targetDepth))
                    {
                        response.LastModified = DateTimeUnmarshaller.GetInstance().Unmarshall(context);

                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    return;
                }
            }


            IWebResponseData responseData = context.ResponseData;

            if (responseData.IsHeaderPresent("x-amz-copy-source-version-id"))
            {
                response.CopySourceVersionId = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-copy-source-version-id"));
            }
            if (responseData.IsHeaderPresent("x-amz-server-side-encryption"))
            {
                response.ServerSideEncryptionMethod = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-server-side-encryption"));
            }


            return;
        }
コード例 #15
0
        private bool HandleRedirect(IExecutionContext executionContext)
        {
            IWebResponseData httpResponse = executionContext.ResponseContext.HttpResponse;

            if (httpResponse.StatusCode >= HttpStatusCode.MultipleChoices && httpResponse.StatusCode < HttpStatusCode.BadRequest)
            {
                if (httpResponse.StatusCode == HttpStatusCode.TemporaryRedirect && httpResponse.IsHeaderPresent("location"))
                {
                    IRequestContext requestContext = executionContext.RequestContext;
                    string          headerValue    = httpResponse.GetHeaderValue("location");
                    requestContext.Metrics.AddProperty(Metric.RedirectLocation, headerValue);
                    if (executionContext.RequestContext.Request.IsRequestStreamRewindable() && !string.IsNullOrEmpty(headerValue))
                    {
                        FinalizeForRedirect(executionContext, headerValue);
                        if (httpResponse.ResponseBody != null)
                        {
                            httpResponse.ResponseBody.Dispose();
                        }
                        return(true);
                    }
                }
                executionContext.ResponseContext.HttpResponse = null;
                throw new HttpErrorResponseException(httpResponse);
            }
            return(false);
        }
コード例 #16
0
        /// <summary>
        /// Wrap the jsonstring for unmarshalling.
        /// </summary>
        /// <param name="responseStream">Stream that contains the JSON for unmarshalling</param>
        /// <param name="maintainResponseBody"> If set to true, maintains a copy of the complete response body as the stream is being read.</param>
        /// <param name="responseData">Response data coming back from the request</param>
        public JsonUnmarshallerContext(Stream responseStream, bool maintainResponseBody, IWebResponseData responseData)
        {
            if (maintainResponseBody)
            {
                this.WrappingStream = new CachingWrapperStream(responseStream);
                responseStream      = this.WrappingStream;
            }

            this.WebResponseData      = responseData;
            this.MaintainResponseBody = maintainResponseBody;

            long contentLength;

            if (responseData != null && long.TryParse(responseData.GetHeaderValue("Content-Length"), out contentLength))
            {
                base.SetupCRCStream(responseData, responseStream, contentLength);
            }

            if (this.CrcStream != null)
            {
                streamReader = new StreamReader(this.CrcStream);
            }
            else
            {
                streamReader = new StreamReader(responseStream);
            }

            jsonReader = new JsonReader(streamReader);
        }
コード例 #17
0
        /// <summary>
        /// Wrap the jsonstring for unmarshalling.
        /// </summary>
        /// <param name="responseStream">Stream that contains the JSON for unmarshalling</param>
        /// <param name="maintainResponseBody"> If set to true, maintains a copy of the complete response body as the stream is being read.</param>
        /// <param name="responseData">Response data coming back from the request</param>
        public JsonUnmarshallerContext(Stream responseStream, bool maintainResponseBody, IWebResponseData responseData)
        {
            if (maintainResponseBody)
            {
                this.WrappingStream = new CachingWrapperStream(responseStream, AWSConfigs.LoggingConfig.LogResponsesSizeLimit);
                responseStream      = this.WrappingStream;
            }

            this.WebResponseData      = responseData;
            this.MaintainResponseBody = maintainResponseBody;

            long contentLength;
            bool parsedContentLengthHeader = long.TryParse(responseData.GetHeaderValue("Content-Length"), out contentLength);

            //possible scenario in unity where the content length in header does not match responseData.ContentLength
            //responseData.ContentLength represents actual bytes downloaded header value represents the length sent from the server.
            //we will only try to setup crc32 in case the responseData.ContentLenth is same as the content lenght from the header.
            //failing to do so may result in the stream being cut off in the middle (since the zip stream length is less than the responseData.ContentLength)
            //or may result in a crc32 exception since the crc32 calcuated value for an unzipped stream will differ from the crc32 values for a zipped stream.
            if (parsedContentLengthHeader && responseData.ContentLength.Equals(contentLength))
            {
                base.SetupCRCStream(responseData, responseStream, contentLength);
            }

            if (this.CrcStream != null)
            {
                streamReader = new StreamReader(this.CrcStream);
            }
            else
            {
                streamReader = new StreamReader(responseStream);
            }

            jsonReader = new JsonReader(streamReader);
        }
コード例 #18
0
        /// <summary>
        /// Wrap the jsonstring for unmarshalling.
        /// </summary>
        /// <param name="responseStream">Stream that contains the JSON for unmarshalling</param>
        /// <param name="maintainResponseBody"> If set to true, maintains a copy of the complete response body as the stream is being read.</param>
        /// <param name="responseData">Response data coming back from the request</param>
        public JsonUnmarshallerContext(Stream responseStream, bool maintainResponseBody, IWebResponseData responseData)
        {
            if (maintainResponseBody)
            {
                this.WrappingStream = new CachingWrapperStream(responseStream, AWSConfigs.LoggingConfig.LogResponsesSizeLimit);
                responseStream = this.WrappingStream;
            }
            
            this.WebResponseData = responseData;
            this.MaintainResponseBody = maintainResponseBody;
			
			long contentLength;
			bool parsedContentLengthHeader = long.TryParse (responseData.GetHeaderValue ("Content-Length"), out contentLength);
 
			//possible scenario in unity where the content length in header does not match responseData.ContentLength
			//responseData.ContentLength represents actual bytes downloaded header value represents the length sent from the server.
			//we will only try to setup crc32 in case the responseData.ContentLenth is same as the content lenght from the header.
			//failing to do so may result in the stream being cut off in the middle (since the zip stream length is less than the responseData.ContentLength)
			//or may result in a crc32 exception since the crc32 calcuated value for an unzipped stream will differ from the crc32 values for a zipped stream.
			if (parsedContentLengthHeader && responseData.ContentLength.Equals (contentLength)) 
			{
                base.SetupCRCStream(responseData, responseStream, contentLength);
            }

            if (this.CrcStream != null)
                streamReader = new StreamReader(this.CrcStream);
            else
                streamReader = new StreamReader(responseStream);

            jsonReader = new JsonReader(streamReader);
        }
コード例 #19
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, DeleteObjectResponse response)
        {
            IWebResponseData responseData = context.ResponseData;

            if (responseData.IsHeaderPresent("x-amz-delete-marker"))
            {
                response.DeleteMarker = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-delete-marker"));
            }
            if (responseData.IsHeaderPresent("x-amz-version-id"))
            {
                response.VersionId = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-version-id"));
            }


            return;
        }
コード例 #20
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, CreateInvalidationResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("Invalidation", targetDepth))
                    {
                        response.Invalidation = InvalidationUnmarshaller.GetInstance().Unmarshall(context);

                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    return;
                }
            }


            IWebResponseData responseData = context.ResponseData;

            if (responseData.IsHeaderPresent("Location"))
            {
                response.Location = responseData.GetHeaderValue("Location");
            }


            return;
        }
コード例 #21
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, UploadPartResponse response)
        {
            IWebResponseData responseData = context.ResponseData;

            if (responseData.IsHeaderPresent("x-amz-server-side-encryption"))
            {
                response.ServerSideEncryptionMethod = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-server-side-encryption"));
            }
            if (responseData.IsHeaderPresent("ETag"))
            {
                response.ETag = S3Transforms.ToString(responseData.GetHeaderValue("ETag"));
            }


            return;
        }
コード例 #22
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, DeleteObjectsResponse response)
        {
            IWebResponseData responseData = context.get_ResponseData();

            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderRequestCharged))
            {
                response.RequestCharged = RequestCharged.FindValue(responseData.GetHeaderValue(S3Constants.AmzHeaderRequestCharged));
            }
            int currentDepth = context.get_CurrentDepth();
            int num          = currentDepth + 1;

            if (context.get_IsStartOfDocument())
            {
                num += 2;
            }
            while (context.Read())
            {
                if (context.get_IsStartElement() || context.get_IsAttribute())
                {
                    if (context.TestExpression("Deleted", num))
                    {
                        response.DeletedObjects.Add(DeletedObjectUnmarshaller.Instance.Unmarshall(context));
                    }
                    else if (context.TestExpression("Error", num))
                    {
                        response.DeleteErrors.Add(ErrorsItemUnmarshaller.Instance.Unmarshall(context));
                    }
                }
                else if (context.get_IsEndElement() && context.get_CurrentDepth() < currentDepth)
                {
                    break;
                }
            }
        }
        private static void UnmarshallResult(XmlUnmarshallerContext context, GetDistributionConfigResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("DistributionConfig", targetDepth))
                    {
                        response.DistributionConfig = DistributionConfigUnmarshaller.GetInstance().Unmarshall(context);

                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    return;
                }
            }


            IWebResponseData responseData = context.ResponseData;

            if (responseData.IsHeaderPresent("ETag"))
            {
                response.ETag = responseData.GetHeaderValue("ETag");
            }


            return;
        }
コード例 #24
0
        protected void SetupFlexibleChecksumStream(IWebResponseData responseData, Stream responseStream, long contentLength, IRequestContext requestContext)
        {
            var algorithm = ChecksumUtils.SelectChecksumForResponseValidation(requestContext?.OriginalRequest?.ChecksumResponseAlgorithms, responseData);

            if (algorithm == CoreChecksumAlgorithm.NONE)
            {
                return;
            }

            ChecksumAlgorithm = algorithm;
            ExpectedFlexibleChecksumResult = responseData.GetHeaderValue(ChecksumUtils.GetChecksumHeaderKey(algorithm));
            var checksum = Convert.FromBase64String(ExpectedFlexibleChecksumResult);

            switch (algorithm)
            {
            case CoreChecksumAlgorithm.CRC32C:
                FlexibleChecksumStream = new HashStream <HashingWrapperCRC32C>(responseStream, checksum, contentLength);
                break;

            case CoreChecksumAlgorithm.CRC32:
                FlexibleChecksumStream = new HashStream <HashingWrapperCRC32>(responseStream, checksum, contentLength);
                break;

            case CoreChecksumAlgorithm.SHA256:
                FlexibleChecksumStream = new HashStream <HashingWrapperSHA256>(responseStream, checksum, contentLength);
                break;

            case CoreChecksumAlgorithm.SHA1:
                FlexibleChecksumStream = new HashStream <HashingWrapperSHA1>(responseStream, checksum, contentLength);
                break;

            default:
                throw new AmazonClientException($"Unsupported checksum algorithm {algorithm}");
            }
        }
コード例 #25
0
        /// <summary>
        /// Shared logic for the HandleException and HandleExceptionAsync
        /// </summary>
        /// <param name="requestContext"></param>
        /// <param name="httpErrorResponse"></param>
        /// <param name="exception"></param>
        /// <param name="responseStream"></param>
        /// <returns></returns>
        private bool HandleExceptionStream(IRequestContext requestContext, IWebResponseData httpErrorResponse, HttpErrorResponseException exception, System.IO.Stream responseStream)
        {
            requestContext.Metrics.AddProperty(Metric.StatusCode, httpErrorResponse.StatusCode);

            AmazonServiceException errorResponseException = null;

            // Unmarshall the service error response and throw the corresponding service exception.
            try
            {
                var unmarshaller       = requestContext.Unmarshaller;
                var readEntireResponse = true;

                var errorContext = unmarshaller.CreateContext(httpErrorResponse,
                                                              readEntireResponse,
                                                              responseStream,
                                                              requestContext.Metrics,
                                                              true,
                                                              requestContext);

                try
                {
                    errorResponseException = unmarshaller.UnmarshallException(errorContext,
                                                                              exception, httpErrorResponse.StatusCode);
                }
                catch (Exception e)
                {
                    // Rethrow Amazon service or client exceptions
                    if (e is AmazonServiceException ||
                        e is AmazonClientException)
                    {
                        throw;
                    }

                    // Else, there was an issue with the response body, throw AmazonUnmarshallingException
                    var requestId = httpErrorResponse.GetHeaderValue(HeaderKeys.RequestIdHeader);
                    var body      = errorContext.ResponseBody;
                    throw new AmazonUnmarshallingException(requestId, lastKnownLocation: null, responseBody: body,
                                                           innerException: e, statusCode: httpErrorResponse.StatusCode);
                }

                requestContext.Metrics.AddProperty(Metric.AWSRequestID, errorResponseException.RequestId);
                requestContext.Metrics.AddProperty(Metric.AWSErrorCode, errorResponseException.ErrorCode);

                var logResponseBody = requestContext.ClientConfig.LogResponse ||
                                      AWSConfigs.LoggingConfig.LogResponses != ResponseLoggingOption.Never;
                if (logResponseBody)
                {
                    this.Logger.Error(errorResponseException, "Received error response: [{0}]",
                                      errorContext.ResponseBody);
                }
            }
            catch (Exception unmarshallException)
            {
                this.Logger.Error(unmarshallException, "Failed to unmarshall a service error response.");
                throw;
            }

            throw errorResponseException;
        }
コード例 #26
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            RestoreObjectResponse response     = new RestoreObjectResponse();
            IWebResponseData      responseData = context.ResponseData;

            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderRequestCharged))
            {
                response.RequestCharged = RequestCharged.FindValue(responseData.GetHeaderValue(S3Constants.AmzHeaderRequestCharged));
            }

            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderRestoreOutputPath))
            {
                response.RestoreOutputPath = responseData.GetHeaderValue(S3Constants.AmzHeaderRestoreOutputPath);
            }

            return(response);
        }
コード例 #27
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, DeleteObjectResponse response)
        {
            IWebResponseData responseData = context.get_ResponseData();

            if (responseData.IsHeaderPresent("x-amz-delete-marker"))
            {
                response.DeleteMarker = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-delete-marker"));
            }
            if (responseData.IsHeaderPresent("x-amz-version-id"))
            {
                response.VersionId = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-version-id"));
            }
            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderRequestCharged))
            {
                response.RequestCharged = RequestCharged.FindValue(responseData.GetHeaderValue(S3Constants.AmzHeaderRequestCharged));
            }
        }
コード例 #28
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, UploadPartResponse response)
        {
            IWebResponseData responseData = context.get_ResponseData();

            if (responseData.IsHeaderPresent("x-amz-server-side-encryption"))
            {
                response.ServerSideEncryptionMethod = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-server-side-encryption"));
            }
            if (responseData.IsHeaderPresent("ETag"))
            {
                response.ETag = S3Transforms.ToString(responseData.GetHeaderValue("ETag"));
            }
            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderRequestCharged))
            {
                response.RequestCharged = RequestCharged.FindValue(responseData.GetHeaderValue(S3Constants.AmzHeaderRequestCharged));
            }
        }
コード例 #29
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, PutObjectTaggingResponse response)
        {
            IWebResponseData responseData = context.get_ResponseData();

            if (responseData.IsHeaderPresent("x-amz-version-id"))
            {
                response.VersionId = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-version-id"));
            }
        }
コード例 #30
0
 protected void SetupCRCStream(IWebResponseData responseData, Stream responseStream, long contentLength)
 {
     CrcStream = null;
     if (responseData != null && uint.TryParse(responseData.GetHeaderValue("x-amz-crc32"), out uint result))
     {
         Crc32Result = (int)result;
         CrcStream   = new CrcCalculatorStream(responseStream, contentLength);
     }
 }
コード例 #31
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, GetObjectTorrentResponse response)
        {
            response.ResponseStream = context.get_Stream();
            IWebResponseData responseData = context.get_ResponseData();

            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderRequestCharged))
            {
                response.RequestCharged = RequestCharged.FindValue(responseData.GetHeaderValue(S3Constants.AmzHeaderRequestCharged));
            }
        }
コード例 #32
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, CopyPartResponse response)
        {
            int currentDepth = context.get_CurrentDepth();
            int num          = currentDepth + 1;

            if (context.get_IsStartOfDocument())
            {
                num += 2;
            }
            while (context.Read())
            {
                if (context.get_IsStartElement() || context.get_IsAttribute())
                {
                    if (context.TestExpression("ETag", num))
                    {
                        response.ETag = StringUnmarshaller.GetInstance().Unmarshall(context);
                    }
                    else if (context.TestExpression("LastModified", num))
                    {
                        response.LastModified = DateTimeUnmarshaller.GetInstance().Unmarshall(context);
                    }
                }
                else if (context.get_IsEndElement() && context.get_CurrentDepth() < currentDepth)
                {
                    return;
                }
            }
            IWebResponseData responseData = context.get_ResponseData();

            if (responseData.IsHeaderPresent("x-amz-copy-source-version-id"))
            {
                response.CopySourceVersionId = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-copy-source-version-id"));
            }
            if (responseData.IsHeaderPresent("x-amz-server-side-encryption"))
            {
                response.ServerSideEncryptionMethod = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-server-side-encryption"));
            }
            if (responseData.IsHeaderPresent("x-amz-server-side-encryption-aws-kms-key-id"))
            {
                response.ServerSideEncryptionKeyManagementServiceKeyId = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-server-side-encryption-aws-kms-key-id"));
            }
        }
コード例 #33
0
        protected void SetupCRCStream(IWebResponseData responseData, Stream responseStream, long contentLength)
        {
            this.CrcStream = null;

            UInt32 parsed;

            if (responseData != null && UInt32.TryParse(responseData.GetHeaderValue("x-amz-crc32"), out parsed))
            {
                this.Crc32Result = (int)parsed;
                this.CrcStream   = new CrcCalculatorStream(responseStream, contentLength);
            }
        }
コード例 #34
0
        /// <summary>
        /// Wrap the jsonstring for unmarshalling.
        /// </summary>
        /// <param name="responseStream">Stream that contains the JSON for unmarshalling</param>
        /// <param name="responseData">Response data coming back from the request</param>
        public JsonUnmarshallerContext(Stream responseStream, IWebResponseData responseData)
        {
            this.WebResponseData = responseData;
            this.ResponseContents = null;

            long contentLength;
            if (responseData != null && long.TryParse(responseData.GetHeaderValue("Content-Length"), out contentLength))
            {
                base.SetupCRCStream(responseData, responseStream, contentLength);
            }

            if (this.CrcStream != null)
                streamReader = new StreamReader(this.CrcStream);
            else
                streamReader = new StreamReader(responseStream);

            jsonReader = new JsonReader(streamReader);
        }
コード例 #35
0
        /// <summary>
        /// Wrap the jsonstring for unmarshalling.
        /// </summary>
        /// <param name="responseStream">Stream that contains the JSON for unmarshalling</param>
        /// <param name="maintainResponseBody"> If set to true, maintains a copy of the complete response body as the stream is being read.</param>
        /// <param name="responseData">Response data coming back from the request</param>
        public JsonUnmarshallerContext(Stream responseStream, bool maintainResponseBody, IWebResponseData responseData)
        {
            if (maintainResponseBody)
            {
                this.WrappingStream = new CachingWrapperStream(responseStream, AWSConfigs.LoggingConfig.LogResponsesSizeLimit);
                responseStream = this.WrappingStream;
            }
            
            this.WebResponseData = responseData;
            this.MaintainResponseBody = maintainResponseBody;
			

            //if the json unmarshaller context is being called internally without their being a http response then the response data would be null
            if(responseData != null)
            {

                long contentLength;
                
                bool parsedContentLengthHeader = long.TryParse(responseData.GetHeaderValue("Content-Length"), out contentLength);

                //possible scenario in unity where the content length in header does not match responseData.ContentLength
                //responseData.ContentLength represents actual bytes downloaded header value represents the length sent from the server.
                //we will only try to setup crc32 in case the responseData.ContentLength is same as the content length from the header.
                //failing to do so may result in the stream being cut off in the middle (since the zip stream length is less than the responseData.ContentLength)
                //or may result in a crc32 exception since the crc32 calcuated value for an unzipped stream will differ from the crc32 values for a zipped stream.
                //
                // Temporary work around checking Content-Encoding for an issue with CoreCLR on Linux returning Content-Length for a gzipped response.
                // Causing the SDK to attempt a CRC check over the gzipped response data with a CRC value for the uncompressed value. 
                // The Content-Encoding check can be removed with the following github issue is shipped.
                // https://github.com/dotnet/corefx/issues/6796
                if (parsedContentLengthHeader && responseData.ContentLength.Equals(contentLength) &&
                    string.IsNullOrEmpty(responseData.GetHeaderValue("Content-Encoding")))
                {
                    base.SetupCRCStream(responseData, responseStream, contentLength);
                }
            }
			
            if (this.CrcStream != null)
                streamReader = new StreamReader(this.CrcStream);
            else
                streamReader = new StreamReader(responseStream);

            jsonReader = new JsonReader(streamReader);
        }
コード例 #36
0
 internal static WebServiceResponseEventArgs Create(AmazonWebServiceResponse response, IRequest request, IWebResponseData webResponseData)
 {
     WebServiceResponseEventArgs args = new WebServiceResponseEventArgs
     {
         RequestHeaders = request.Headers,
         Parameters = request.Parameters,
         ServiceName = request.ServiceName,
         Request = request.OriginalRequest,
         Endpoint = request.Endpoint,
         Response = response
     };
     args.ResponseHeaders = new Dictionary<string, string>();
     var headerNames = webResponseData.GetHeaderNames();
     foreach (var responseHeaderName in headerNames)
     {
         string responseHeaderValue = webResponseData.GetHeaderValue(responseHeaderName);
         args.ResponseHeaders[responseHeaderName] = responseHeaderValue;
     }
     return args;
 }
コード例 #37
0
        /// <summary>
        /// Wrap the jsonstring for unmarshalling.
        /// </summary>
        /// <param name="responseStream">Stream that contains the JSON for unmarshalling</param>
        /// <param name="maintainResponseBody"> If set to true, maintains a copy of the complete response body as the stream is being read.</param>
        /// <param name="responseData">Response data coming back from the request</param>
        public JsonUnmarshallerContext(Stream responseStream, bool maintainResponseBody, IWebResponseData responseData)
        {
            if (maintainResponseBody)
            {
                this.WrappingStream = new CachingWrapperStream(responseStream);
                responseStream = this.WrappingStream;
            }
            
            this.WebResponseData = responseData;
            this.MaintainResponseBody = maintainResponseBody;

            long contentLength;
            if (responseData != null && long.TryParse(responseData.GetHeaderValue("Content-Length"), out contentLength))
            {
                base.SetupCRCStream(responseData, responseStream, contentLength);
            }

            if (this.CrcStream != null)
                streamReader = new StreamReader(this.CrcStream);
            else
                streamReader = new StreamReader(responseStream);

            jsonReader = new JsonReader(streamReader);
        }
コード例 #38
0
 private static bool HasSSEHeaders(IWebResponseData webResponseData)
 {
     bool usesCustomerAlgorithm = !string.IsNullOrEmpty(webResponseData.GetHeaderValue(HeaderKeys.XAmzSSECustomerAlgorithmHeader));
     bool usesKmsKeyId = !string.IsNullOrEmpty(webResponseData.GetHeaderValue(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader));
     return usesCustomerAlgorithm || usesKmsKeyId;
 }
コード例 #39
0
 public override UnmarshallerContext CreateContext(IWebResponseData response, bool readEntireResponse, Stream stream, RequestMetrics metrics)
 {
     if (response.IsHeaderPresent(AMZ_ID_2))
         metrics.AddProperty(Metric.AmzId2, response.GetHeaderValue(AMZ_ID_2));
     return base.CreateContext(response, readEntireResponse, stream, metrics);
 }