/// <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);
        }
 public AmazonServiceException UnmarshallException(IWebResponseData response, ErrorResponse errorResponse, Exception innerException)
 {
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("InternalError"))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new InternalErrorException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("InvalidConfiguration"))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new InvalidConfigurationException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("InvalidParameter"))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new InvalidParameterException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("NotAuthorizedError"))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new NotAuthorizedException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("ResourceNotFound"))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new ResourceNotFoundException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("TooManyRequests"))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new TooManyRequestsException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     return new AmazonCognitoSyncException(GetDefaultErrorMessage<AmazonCognitoSyncException>(), innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
 }
 /// <summary>
 /// Constructs a new instance of the HttpErrorResponseException class with serialized data.
 /// </summary>
 /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object data about the exception being thrown.</param>
 /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains contextual information about the source or destination.</param>
 /// <exception cref="T:System.ArgumentNullException">The <paramref name="info" /> parameter is null. </exception>
 /// <exception cref="T:System.Runtime.Serialization.SerializationException">The class name is null or <see cref="P:System.Exception.HResult" /> is zero (0). </exception>
 protected HttpErrorResponseException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
     : base(info, context)
 {
     if (info != null)
     {
         this.Response = (IWebResponseData)info.GetValue("Response", typeof(IWebResponseData));
     }
 }
 public AmazonServiceException UnmarshallException(IWebResponseData response, ErrorResponse errorResponse, Exception innerException)
 {
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("BadRequestException"))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonMobileAnalyticsException>():errorResponse.Message;
         return new BadRequestException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     return new AmazonMobileAnalyticsException(GetDefaultErrorMessage<AmazonMobileAnalyticsException>(), innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
 }
Example #5
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);
        }
        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);
        }
        /// <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);
        }
        /// <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);
        }
 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;
 }
        /// <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);
        }
        protected override void ProcessResponseHandlers(AmazonWebServiceResponse response, IRequest request, IWebResponseData webResponseData)
        {
            base.ProcessResponseHandlers(response, request, webResponseData);

            ReceiveMessageResponse receiveMessageResponse = response as ReceiveMessageResponse;
            if (receiveMessageResponse != null)
            {
                ValidateReceiveMessage(receiveMessageResponse);
            }

            SendMessageResponse sendMessageResponse = response as SendMessageResponse;
            SendMessageRequest sendMessageRequest = request.OriginalRequest as SendMessageRequest;
            if (sendMessageRequest != null && sendMessageResponse != null)
            {
                ValidateSendMessage(sendMessageRequest, sendMessageResponse);
            }

            SendMessageBatchRequest sendMessageBatchRequest = request.OriginalRequest as SendMessageBatchRequest;
            SendMessageBatchResponse sendMessageBatchResponse = response as SendMessageBatchResponse;
            if (sendMessageBatchRequest != null && sendMessageBatchResponse != null)
            {
                ValidateSendMessageBatch(sendMessageBatchRequest, sendMessageBatchResponse);
            }
        }
 public HttpErrorResponseException(IWebResponseData response)
 {
     this.Response = response;
 }
 protected override bool ShouldReadEntireResponse(IWebResponseData response, bool readEntireResponse)
 {
     return(readEntireResponse && response.ContentType != "application/octet-stream");
 }
        /// <summary>
        /// Wrap the jsonstring for unmarshalling.
        /// </summary>
        /// <param name="responseBody">String that contains the JSON for unmarshalling</param>
        /// <param name="responseData">Response data coming back from the request</param>
        public JsonUnmarshallerContext(string responseBody, IWebResponseData responseData)
        {
            this.WebResponseData = responseData;
            this.ResponseContents = responseBody;

            var stream = new MemoryStream(Encoding.UTF8.GetBytes(responseBody));
            base.SetupCRCStream(responseData, stream, stream.Length);

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

            jsonReader = new JsonReader(streamReader);
        }
 public AmazonServiceException UnmarshallException(IWebResponseData response, ErrorResponse errorResponse, Exception innerException)
 {
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("ConcurrentModificationException", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoIdentityException>():errorResponse.Message;
         return new ConcurrentModificationException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("InternalErrorException", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoIdentityException>():errorResponse.Message;
         return new InternalErrorException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("InvalidParameterException", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoIdentityException>():errorResponse.Message;
         return new InvalidParameterException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("NotAuthorizedException", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoIdentityException>():errorResponse.Message;
         return new NotAuthorizedException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("ResourceConflictException", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoIdentityException>():errorResponse.Message;
         return new ResourceConflictException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("ResourceNotFoundException", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoIdentityException>():errorResponse.Message;
         return new ResourceNotFoundException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("TooManyRequestsException", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoIdentityException>():errorResponse.Message;
         return new TooManyRequestsException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     return new AmazonCognitoIdentityException(GetDefaultErrorMessage<AmazonCognitoIdentityException>(), innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
 }
Example #16
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>();
            if (webResponseData != null)
            {
                var headerNames = webResponseData.GetHeaderNames();
                foreach (var responseHeaderName in headerNames)
                {
                    string responseHeaderValue = webResponseData.GetHeaderValue(responseHeaderName);
                    args.ResponseHeaders[responseHeaderName] = responseHeaderValue;
                }
            }
            return(args);
        }
 public XmlUnmarshallerContext(Stream responseStream, IWebResponseData responseData)
 {
     this.ResponseStream = responseStream;
     this.WebResponseData = responseData;
 }
Example #18
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, GetObjectMetadataResponse 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("accept-ranges"))
            {
                response.AcceptRanges = S3Transforms.ToString(responseData.GetHeaderValue("accept-ranges"));
            }
            if (responseData.IsHeaderPresent("x-amz-expiration"))
            {
                response.Expiration = new Expiration(responseData.GetHeaderValue("x-amz-expiration"));
            }
            if (responseData.IsHeaderPresent("x-amz-restore"))
            {
                AmazonS3Util.ParseAmzRestoreHeader(responseData.GetHeaderValue("x-amz-restore"), out bool restoreInProgress, out DateTime? restoreExpiration);
                response.RestoreInProgress = restoreInProgress;
                response.RestoreExpiration = restoreExpiration;
            }
            if (responseData.IsHeaderPresent("Last-Modified"))
            {
                response.LastModified = S3Transforms.ToDateTime(responseData.GetHeaderValue("Last-Modified"));
            }
            if (responseData.IsHeaderPresent("ETag"))
            {
                response.ETag = S3Transforms.ToString(responseData.GetHeaderValue("ETag"));
            }
            if (responseData.IsHeaderPresent("x-amz-missing-meta"))
            {
                response.MissingMeta = S3Transforms.ToInt(responseData.GetHeaderValue("x-amz-missing-meta"));
            }
            if (responseData.IsHeaderPresent("x-amz-version-id"))
            {
                response.VersionId = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-version-id"));
            }
            if (responseData.IsHeaderPresent("Cache-Control"))
            {
                response.Headers.CacheControl = S3Transforms.ToString(responseData.GetHeaderValue("Cache-Control"));
            }
            if (responseData.IsHeaderPresent("Content-Disposition"))
            {
                response.Headers.ContentDisposition = S3Transforms.ToString(responseData.GetHeaderValue("Content-Disposition"));
            }
            if (responseData.IsHeaderPresent("Content-Encoding"))
            {
                response.Headers.ContentEncoding = S3Transforms.ToString(responseData.GetHeaderValue("Content-Encoding"));
            }
            if (responseData.IsHeaderPresent("Content-Length"))
            {
                response.Headers.ContentLength = long.Parse(responseData.GetHeaderValue("Content-Length"), CultureInfo.InvariantCulture);
            }
            if (responseData.IsHeaderPresent("Content-Type"))
            {
                response.Headers.ContentType = S3Transforms.ToString(responseData.GetHeaderValue("Content-Type"));
            }
            if (responseData.IsHeaderPresent("Expires"))
            {
                response.RawExpires = S3Transforms.ToString(responseData.GetHeaderValue("Expires"));
            }
            if (responseData.IsHeaderPresent("x-amz-website-redirect-location"))
            {
                response.WebsiteRedirectLocation = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-website-redirect-location"));
            }
            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-customer-algorithm"))
            {
                response.ServerSideEncryptionCustomerMethod = ServerSideEncryptionCustomerMethod.FindValue(responseData.GetHeaderValue("x-amz-server-side-encryption-customer-algorithm"));
            }
            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("x-amz-replication-status"))
            {
                response.ReplicationStatus = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-replication-status"));
            }
            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderMultipartPartsCount))
            {
                response.PartsCount = S3Transforms.ToInt(responseData.GetHeaderValue(S3Constants.AmzHeaderMultipartPartsCount));
            }
            if (responseData.IsHeaderPresent("x-amz-storage-class"))
            {
                response.StorageClass = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-storage-class"));
            }
            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderRequestCharged))
            {
                response.RequestCharged = RequestCharged.FindValue(responseData.GetHeaderValue(S3Constants.AmzHeaderRequestCharged));
            }
            string[] headerNames = responseData.GetHeaderNames();
            foreach (string text in headerNames)
            {
                if (text.StartsWith("x-amz-meta-", StringComparison.OrdinalIgnoreCase))
                {
                    response.Metadata[text] = responseData.GetHeaderValue(text);
                }
            }
        }
 protected override UnmarshallerContext ConstructUnmarshallerContext(Stream responseStream, bool maintainResponseBody, IWebResponseData response)
 {
     return(new XmlUnmarshallerContext(responseStream, maintainResponseBody, response));
 }
Example #20
0
 protected override UnmarshallerContext ConstructUnmarshallerContext(
     Stream responseStream, bool maintainResponseBody,
     IWebResponseData response, bool isException) =>
 new NonHttpUnmarshallerContext((NonHttpResponseData)response);
Example #21
0
 protected override bool ShouldReadEntireResponse(IWebResponseData response, bool readEntireResponse) =>
 false;
Example #22
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, ListPartsResponse 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("Bucket", targetDepth))
                    {
                        response.BucketName = StringUnmarshaller.GetInstance().Unmarshall(context);

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

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

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

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

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

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

                        continue;
                    }
                    if (context.TestExpression("Part", targetDepth))
                    {
                        response.Parts.Add(PartDetailUnmarshaller.Instance.Unmarshall(context));

                        continue;
                    }
                    if (context.TestExpression("Initiator", targetDepth))
                    {
                        response.Initiator = InitiatorUnmarshaller.Instance.Unmarshall(context);

                        continue;
                    }
                    if (context.TestExpression("Owner", targetDepth))
                    {
                        response.Owner = OwnerUnmarshaller.Instance.Unmarshall(context);

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

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

            IWebResponseData responseData = context.ResponseData;

            if (responseData.IsHeaderPresent(HeaderKeys.XAmzAbortDateHeader))
            {
                response.AbortDate = S3Transforms.ToDateTime(responseData.GetHeaderValue(HeaderKeys.XAmzAbortDateHeader));
            }
            if (responseData.IsHeaderPresent(HeaderKeys.XAmzAbortRuleIdHeader))
            {
                response.AbortRuleId = S3Transforms.ToString(responseData.GetHeaderValue(HeaderKeys.XAmzAbortRuleIdHeader));
            }

            return;
        }
        private static void UnmarshallResult(XmlUnmarshallerContext context, GetObjectMetadataResponse 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("accept-ranges"))
            {
                response.AcceptRanges = S3Transforms.ToString(responseData.GetHeaderValue("accept-ranges"));
            }
            if (context.ResponseData.IsHeaderPresent("content-range"))
            {
                response.ContentRange = S3Transforms.ToString(responseData.GetHeaderValue("content-range"));
            }
            if (responseData.IsHeaderPresent("x-amz-expiration"))
            {
                response.Expiration = new Expiration(responseData.GetHeaderValue("x-amz-expiration"));
            }
            if (responseData.IsHeaderPresent("x-amz-restore"))
            {
                bool     restoreInProgress;
                DateTime?restoreExpiration;
                AmazonS3Util.ParseAmzRestoreHeader(responseData.GetHeaderValue("x-amz-restore"), out restoreInProgress, out restoreExpiration);

                response.RestoreInProgress = restoreInProgress;
                response.RestoreExpiration = restoreExpiration;
            }
            if (responseData.IsHeaderPresent("Last-Modified"))
            {
                response.LastModified = S3Transforms.ToDateTime(responseData.GetHeaderValue("Last-Modified"));
            }
            if (responseData.IsHeaderPresent("ETag"))
            {
                response.ETag = S3Transforms.ToString(responseData.GetHeaderValue("ETag"));
            }
            if (responseData.IsHeaderPresent("x-amz-missing-meta"))
            {
                response.MissingMeta = S3Transforms.ToInt(responseData.GetHeaderValue("x-amz-missing-meta"));
            }
            if (responseData.IsHeaderPresent("x-amz-version-id"))
            {
                response.VersionId = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-version-id"));
            }
            if (responseData.IsHeaderPresent("Cache-Control"))
            {
                response.Headers.CacheControl = S3Transforms.ToString(responseData.GetHeaderValue("Cache-Control"));
            }
            if (responseData.IsHeaderPresent("Content-Disposition"))
            {
                response.Headers.ContentDisposition = S3Transforms.ToString(responseData.GetHeaderValue("Content-Disposition"));
            }
            if (responseData.IsHeaderPresent("Content-Encoding"))
            {
                response.Headers.ContentEncoding = S3Transforms.ToString(responseData.GetHeaderValue("Content-Encoding"));
            }
            if (responseData.IsHeaderPresent("Content-Length"))
            {
                response.Headers.ContentLength = long.Parse(responseData.GetHeaderValue("Content-Length"), CultureInfo.InvariantCulture);
            }
            if (responseData.IsHeaderPresent("Content-Type"))
            {
                response.Headers.ContentType = S3Transforms.ToString(responseData.GetHeaderValue("Content-Type"));
            }
            if (responseData.IsHeaderPresent("Expires"))
            {
                response.RawExpires = S3Transforms.ToString(responseData.GetHeaderValue("Expires"));
            }
            if (responseData.IsHeaderPresent("x-amz-website-redirect-location"))
            {
                response.WebsiteRedirectLocation = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-website-redirect-location"));
            }
            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-customer-algorithm"))
            {
                response.ServerSideEncryptionCustomerMethod = ServerSideEncryptionCustomerMethod.FindValue(responseData.GetHeaderValue("x-amz-server-side-encryption-customer-algorithm"));
            }
            if (responseData.IsHeaderPresent(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader))
            {
                response.ServerSideEncryptionKeyManagementServiceKeyId = S3Transforms.ToString(responseData.GetHeaderValue(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader));
            }
            if (responseData.IsHeaderPresent("x-amz-replication-status"))
            {
                response.ReplicationStatus = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-replication-status"));
            }
            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderMultipartPartsCount))
            {
                response.PartsCount = S3Transforms.ToInt(responseData.GetHeaderValue(S3Constants.AmzHeaderMultipartPartsCount));
            }
            if (responseData.IsHeaderPresent("x-amz-object-lock-mode"))
            {
                response.ObjectLockMode = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-object-lock-mode"));
            }
            if (responseData.IsHeaderPresent("x-amz-object-lock-retain-until-date"))
            {
                response.ObjectLockRetainUntilDate = S3Transforms.ToDateTime(responseData.GetHeaderValue("x-amz-object-lock-retain-until-date"));
            }
            if (responseData.IsHeaderPresent("x-amz-object-lock-legal-hold"))
            {
                response.ObjectLockLegalHoldStatus = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-object-lock-legal-hold"));
            }
            if (responseData.IsHeaderPresent(HeaderKeys.XAmzStorageClassHeader))
            {
                response.StorageClass = S3Transforms.ToString(responseData.GetHeaderValue(HeaderKeys.XAmzStorageClassHeader));
            }
            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderRequestCharged))
            {
                response.RequestCharged = RequestCharged.FindValue(responseData.GetHeaderValue(S3Constants.AmzHeaderRequestCharged));
            }
            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderArchiveStatus))
            {
                response.ArchiveStatus = S3Transforms.ToString(responseData.GetHeaderValue(S3Constants.AmzHeaderArchiveStatus));
            }
            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderBucketKeyEnabled))
            {
                response.BucketKeyEnabled = S3Transforms.ToBool(responseData.GetHeaderValue(S3Constants.AmzHeaderBucketKeyEnabled));
            }

            foreach (var name in responseData.GetHeaderNames())
            {
                if (name.StartsWith("x-amz-meta-", StringComparison.OrdinalIgnoreCase))
                {
                    response.Metadata[name] = AWSConfigsS3.EnableUnicodeEncodingForObjectMetadata
                        ? Uri.UnescapeDataString(responseData.GetHeaderValue(name)) : responseData.GetHeaderValue(name);
                }
            }

            return;
        }
 public XmlUnmarshallerContext(Stream responseStream, IWebResponseData responseData)
 {
     this.ResponseStream  = responseStream;
     this.WebResponseData = responseData;
 }
Example #25
0
 public HttpErrorResponseException(string message, IWebResponseData response)
     : base(message)
 {
     Response = response;
 }
        protected override void ProcessResponseHandlers(AmazonWebServiceResponse response, IRequest request, IWebResponseData webResponseData)
        {
            base.ProcessResponseHandlers(response, request, webResponseData);

            ReceiveMessageResponse receiveMessageResponse = response as ReceiveMessageResponse;

            if (receiveMessageResponse != null)
            {
                ValidateReceiveMessage(receiveMessageResponse);
            }

            SendMessageResponse sendMessageResponse = response as SendMessageResponse;
            SendMessageRequest  sendMessageRequest  = request.OriginalRequest as SendMessageRequest;

            if (sendMessageRequest != null && sendMessageResponse != null)
            {
                ValidateSendMessage(sendMessageRequest, sendMessageResponse);
            }

            SendMessageBatchRequest  sendMessageBatchRequest  = request.OriginalRequest as SendMessageBatchRequest;
            SendMessageBatchResponse sendMessageBatchResponse = response as SendMessageBatchResponse;

            if (sendMessageBatchRequest != null && sendMessageBatchResponse != null)
            {
                ValidateSendMessageBatch(sendMessageBatchRequest, sendMessageBatchResponse);
            }
        }
        /// <summary>
        /// Performs decryption of data by getting encryption information
        /// from object metadata or instruction file.
        /// </summary>
        /// <param name="response">AmazonWebServiceResponse on which decryption is performed</param>
        /// <param name="request">IRequest</param>
        /// <param name="webResponseData">IWebResponseData</param>
        protected override void ProcessResponseHandlers(AmazonWebServiceResponse response, IRequest request, IWebResponseData webResponseData)
        {
            base.ProcessResponseHandlers(response, request, webResponseData);

            var initiateMultiPartUploadRequest = request.OriginalRequest as InitiateMultipartUploadRequest;
            var initiateMultiPartResponse = response as InitiateMultipartUploadResponse;
            if (initiateMultiPartResponse != null)
            {
                byte[] envelopeKey = initiateMultiPartUploadRequest.EnvelopeKey;
                byte[] iv = initiateMultiPartUploadRequest.IV;

                UploadPartEncryptionContext contextForEncryption = new UploadPartEncryptionContext();
                contextForEncryption.EnvelopeKey = envelopeKey;
                contextForEncryption.NextIV = iv;
                contextForEncryption.FirstIV = iv;
                contextForEncryption.PartNumber = 0;

                //Add context for encryption of next part
                currentMultiPartUploadKeys.Add(initiateMultiPartResponse.UploadId, contextForEncryption);
            }

            var uploadPartRequest = request.OriginalRequest as UploadPartRequest;
            var uploadPartResponse = response as UploadPartResponse;
            if (uploadPartResponse != null)
            {
                string uploadID = uploadPartRequest.UploadId;
                UploadPartEncryptionContext encryptedUploadedContext = null;

                if (!currentMultiPartUploadKeys.TryGetValue(uploadID, out encryptedUploadedContext))
                    throw new AmazonS3Exception("encryption context for multi part upload not found");

                if (uploadPartRequest.IsLastPart == false)
                {
                    object stream = null;

                    if (!uploadPartRequest.RequestState.TryGetValue(S3CryptoStream, out stream))
                        throw new AmazonS3Exception("cannot retrieve S3 crypto stream from request state, hence cannot get Initialization vector for next uploadPart ");

                    var encryptionStream = stream as AESEncryptionUploadPartStream;
                    encryptedUploadedContext.NextIV = encryptionStream.InitializationVector;
                }

            }

            var getObjectResponse = response as GetObjectResponse;
            if (getObjectResponse != null)
            {
                if (EncryptionUtils.IsEncryptionInfoInMetadata(getObjectResponse) == true)
                {
                    DecryptObjectUsingMetadata(getObjectResponse);
                }
                else
                {
                    GetObjectResponse instructionFileResponse = null;
                    try
                    {
                        GetObjectRequest instructionFileRequest = EncryptionUtils.GetInstructionFileRequest(getObjectResponse);
                        instructionFileResponse = S3ClientForInstructionFile.GetObject(instructionFileRequest);
                    }
                    catch (AmazonServiceException ace)
                    {
                        throw new AmazonServiceException(string.Format(CultureInfo.InvariantCulture, "Unable to decrypt data for object {0} in bucket {1}",
                            getObjectResponse.Key, getObjectResponse.BucketName), ace);
                    }

                    if (EncryptionUtils.IsEncryptionInfoInInstructionFile(instructionFileResponse) == true)
                    {
                        DecryptObjectUsingInstructionFile(getObjectResponse, instructionFileResponse);
                    }
                }
            }

            var completeMultiPartUploadRequest = request.OriginalRequest as CompleteMultipartUploadRequest;
            var completeMultipartUploadResponse = response as CompleteMultipartUploadResponse;
            if (completeMultipartUploadResponse != null)
            {
                if (amazonS3CryptoConfig.StorageMode == CryptoStorageMode.InstructionFile)
                {
                    UploadPartEncryptionContext context = currentMultiPartUploadKeys[completeMultiPartUploadRequest.UploadId];
                    byte[] envelopeKey = context.EnvelopeKey;
                    byte[] iv = context.FirstIV;
                    byte[] encryptedEnvelopeKey = EncryptionUtils.EncryptEnvelopeKey(envelopeKey, this.encryptionMaterials);
                    EncryptionInstructions instructions = new EncryptionInstructions(EncryptionMaterials.EmptyMaterialsDescription, envelopeKey, encryptedEnvelopeKey, iv);

                    PutObjectRequest instructionFileRequest = EncryptionUtils.CreateInstructionFileRequest(completeMultiPartUploadRequest, instructions);

                    S3ClientForInstructionFile.PutObject(instructionFileRequest);
                }

                //Clear Context data since encryption is completed
                currentMultiPartUploadKeys.Clear();
            }
        }
Example #28
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);
        }
Example #29
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, GetObjectResponse response)
        {
            response.ResponseStream = context.Stream;

            IWebResponseData responseData = context.ResponseData;

            if (responseData.IsHeaderPresent("x-amz-delete-marker"))
            {
                response.DeleteMarker = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-delete-marker"));
            }
            if (responseData.IsHeaderPresent("accept-ranges"))
            {
                response.AcceptRanges = S3Transforms.ToString(responseData.GetHeaderValue("accept-ranges"));
            }
            if (responseData.IsHeaderPresent("x-amz-expiration"))
            {
                response.Expiration = new Expiration(responseData.GetHeaderValue("x-amz-expiration"));
            }
            if (responseData.IsHeaderPresent("x-amz-restore"))
            {
                bool     restoreInProgress;
                DateTime?restoreExpiration;
                AmazonS3Util.ParseAmzRestoreHeader(responseData.GetHeaderValue("x-amz-restore"), out restoreInProgress, out restoreExpiration);

                response.RestoreInProgress = restoreInProgress;
                response.RestoreExpiration = restoreExpiration;
            }
            if (responseData.IsHeaderPresent("Last-Modified"))
            {
                response.LastModified = S3Transforms.ToDateTime(responseData.GetHeaderValue("Last-Modified"));
            }
            if (responseData.IsHeaderPresent("ETag"))
            {
                response.ETag = S3Transforms.ToString(responseData.GetHeaderValue("ETag"));
            }
            if (responseData.IsHeaderPresent("x-amz-missing-meta"))
            {
                response.MissingMeta = S3Transforms.ToInt(responseData.GetHeaderValue("x-amz-missing-meta"));
            }
            if (responseData.IsHeaderPresent("x-amz-version-id"))
            {
                response.VersionId = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-version-id"));
            }
            if (responseData.IsHeaderPresent("Cache-Control"))
            {
                response.Headers.CacheControl = S3Transforms.ToString(responseData.GetHeaderValue("Cache-Control"));
            }
            if (responseData.IsHeaderPresent("Content-Disposition"))
            {
                response.Headers.ContentDisposition = S3Transforms.ToString(responseData.GetHeaderValue("Content-Disposition"));
            }
            if (responseData.IsHeaderPresent("Content-Encoding"))
            {
                response.Headers.ContentEncoding = S3Transforms.ToString(responseData.GetHeaderValue("Content-Encoding"));
            }
            if (responseData.IsHeaderPresent("Content-Length"))
            {
                response.Headers.ContentLength = long.Parse(responseData.GetHeaderValue("Content-Length"), CultureInfo.InvariantCulture);
            }
            if (responseData.IsHeaderPresent("Content-Type"))
            {
                response.Headers.ContentType = S3Transforms.ToString(responseData.GetHeaderValue("Content-Type"));
            }
            if (responseData.IsHeaderPresent("Expires"))
            {
                response.Expires = S3Transforms.ToDateTime(responseData.GetHeaderValue("Expires"));
            }
            if (responseData.IsHeaderPresent("x-amz-website-redirect-location"))
            {
                response.WebsiteRedirectLocation = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-website-redirect-location"));
            }
            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-customer-algorithm"))
            {
                response.ServerSideEncryptionCustomerMethod = ServerSideEncryptionCustomerMethod.FindValue(responseData.GetHeaderValue("x-amz-server-side-encryption-customer-algorithm"));
            }
            if (responseData.IsHeaderPresent(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader))
            {
                response.ServerSideEncryptionKeyManagementServiceKeyId = S3Transforms.ToString(responseData.GetHeaderValue(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader));
            }
            if (responseData.IsHeaderPresent("x-amz-replication-status"))
            {
                response.ReplicationStatus = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-replication-status"));
            }
            if (responseData.IsHeaderPresent(HeaderKeys.XAmzStorageClassHeader))
            {
                response.StorageClass = S3Transforms.ToString(responseData.GetHeaderValue(HeaderKeys.XAmzStorageClassHeader));
            }

            foreach (var name in responseData.GetHeaderNames())
            {
                if (name.StartsWith("x-amz-meta-", StringComparison.OrdinalIgnoreCase))
                {
                    response.Metadata[name] = responseData.GetHeaderValue(name);
                }
            }

            return;
        }
Example #30
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, CompleteMultipartUploadResponse 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("Location", targetDepth))
                    {
                        response.Location = StringUnmarshaller.GetInstance().Unmarshall(context);

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

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

                        continue;
                    }
                    if (context.TestExpression("ETag", targetDepth))
                    {
                        response.ETag = 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-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"));
            }


            return;
        }
        /// <summary>
        /// Wrap the jsonstring for unmarshalling.
        /// </summary>
        /// <param name="responseBody">String that contains the JSON for unmarshalling</param>
        /// <param name="responseData">Response data coming back from the request</param>
        public JsonUnmarshallerContext(string responseBody, IWebResponseData responseData)
        {
            this.WebResponseData = responseData;
            this.ResponseContents = responseBody;

            streamReader = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(responseBody)));
            jsonReader = new JsonReader(streamReader);
        }
Example #32
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, InitiateMultipartUploadResponse 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("Bucket", targetDepth))
                    {
                        response.BucketName = StringUnmarshaller.GetInstance().Unmarshall(context);

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

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

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


            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("x-amz-server-side-encryption-customer-algorithm"))
            {
                response.ServerSideEncryptionCustomerMethod = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-server-side-encryption-customer-algorithm"));
            }
            if (responseData.IsHeaderPresent("x-amz-server-side-encryption-customer-key-MD5"))
            {
                response.ServerSideEncryptionCustomerProvidedKeyMD5 = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-server-side-encryption-customer-key-MD5"));
            }
            if (responseData.IsHeaderPresent(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader))
            {
                response.ServerSideEncryptionKeyManagementServiceKeyId = S3Transforms.ToString(responseData.GetHeaderValue(HeaderKeys.XAmzServerSideEncryptionAwsKmsKeyIdHeader));
            }
            if (responseData.IsHeaderPresent("x-amz-server-side-encryption-context"))
            {
                response.ServerSideEncryptionKeyManagementServiceEncryptionContext = S3Transforms.ToString(responseData.GetHeaderValue("x-amz-server-side-encryption-context"));
            }
            if (responseData.IsHeaderPresent(HeaderKeys.XAmzAbortDateHeader))
            {
                response.AbortDate = S3Transforms.ToDateTime(responseData.GetHeaderValue(HeaderKeys.XAmzAbortDateHeader));
            }
            if (responseData.IsHeaderPresent(HeaderKeys.XAmzAbortRuleIdHeader))
            {
                response.AbortRuleId = S3Transforms.ToString(responseData.GetHeaderValue(HeaderKeys.XAmzAbortRuleIdHeader));
            }
            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderRequestCharged))
            {
                response.RequestCharged = RequestCharged.FindValue(responseData.GetHeaderValue(S3Constants.AmzHeaderRequestCharged));
            }
            if (responseData.IsHeaderPresent(S3Constants.AmzHeaderBucketKeyEnabled))
            {
                response.BucketKeyEnabled = S3Transforms.ToBool(responseData.GetHeaderValue(S3Constants.AmzHeaderBucketKeyEnabled));
            }
            return;
        }
 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;
 }
 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);
 }
 protected virtual bool ShouldReadEntireResponse(IWebResponseData response, bool readEntireResponse)
 {
     return(readEntireResponse);
 }
        /// <summary>
        /// Performs decryption of data by getting encryption information
        /// from object metadata or instruction file.
        /// </summary>
        /// <param name="response">AmazonWebServiceResponse on which decryption is performed</param>
        /// <param name="request">IRequest</param>
        /// <param name="webResponseData">IWebResponseData</param>
        protected override void ProcessResponseHandlers(AmazonWebServiceResponse response, IRequest request, IWebResponseData webResponseData)
        {
            base.ProcessResponseHandlers(response, request, webResponseData);

            var initiateMultiPartUploadRequest = request.OriginalRequest as InitiateMultipartUploadRequest;
            var initiateMultiPartResponse      = response as InitiateMultipartUploadResponse;

            if (initiateMultiPartResponse != null)
            {
                byte[] envelopeKey = initiateMultiPartUploadRequest.EnvelopeKey;
                byte[] iv          = initiateMultiPartUploadRequest.IV;

                UploadPartEncryptionContext contextForEncryption = new UploadPartEncryptionContext();
                contextForEncryption.EnvelopeKey = envelopeKey;
                contextForEncryption.NextIV      = iv;
                contextForEncryption.FirstIV     = iv;
                contextForEncryption.PartNumber  = 0;

                //Add context for encryption of next part
                currentMultiPartUploadKeys.Add(initiateMultiPartResponse.UploadId, contextForEncryption);
            }

            var uploadPartRequest  = request.OriginalRequest as UploadPartRequest;
            var uploadPartResponse = response as UploadPartResponse;

            if (uploadPartResponse != null)
            {
                string uploadID = uploadPartRequest.UploadId;
                UploadPartEncryptionContext encryptedUploadedContext = null;

                if (!currentMultiPartUploadKeys.TryGetValue(uploadID, out encryptedUploadedContext))
                {
                    throw new AmazonS3Exception("encryption context for multi part upload not found");
                }

                if (uploadPartRequest.IsLastPart == false)
                {
                    object stream = null;

                    if (!uploadPartRequest.RequestState.TryGetValue(S3CryptoStream, out stream))
                    {
                        throw new AmazonS3Exception("cannot retrieve S3 crypto stream from request state, hence cannot get Initialization vector for next uploadPart ");
                    }

                    var encryptionStream = stream as AESEncryptionUploadPartStream;
                    encryptedUploadedContext.NextIV = encryptionStream.InitializationVector;
                }
            }

            var getObjectResponse = response as GetObjectResponse;

            if (getObjectResponse != null)
            {
                if (EncryptionUtils.IsEncryptionInfoInMetadata(getObjectResponse) == true)
                {
                    DecryptObjectUsingMetadata(getObjectResponse);
                }
                else
                {
                    GetObjectResponse instructionFileResponse = null;
                    try
                    {
                        GetObjectRequest instructionFileRequest = EncryptionUtils.GetInstructionFileRequest(getObjectResponse);
                        instructionFileResponse = S3ClientForInstructionFile.GetObject(instructionFileRequest);
                    }
                    catch (AmazonServiceException ace)
                    {
                        throw new AmazonServiceException(string.Format(CultureInfo.InvariantCulture, "Unable to decrypt data for object {0} in bucket {1}",
                                                                       getObjectResponse.Key, getObjectResponse.BucketName), ace);
                    }

                    if (EncryptionUtils.IsEncryptionInfoInInstructionFile(instructionFileResponse) == true)
                    {
                        DecryptObjectUsingInstructionFile(getObjectResponse, instructionFileResponse);
                    }
                }
            }

            var completeMultiPartUploadRequest  = request.OriginalRequest as CompleteMultipartUploadRequest;
            var completeMultipartUploadResponse = response as CompleteMultipartUploadResponse;

            if (completeMultipartUploadResponse != null)
            {
                if (amazonS3CryptoConfig.StorageMode == CryptoStorageMode.InstructionFile)
                {
                    UploadPartEncryptionContext context = currentMultiPartUploadKeys[completeMultiPartUploadRequest.UploadId];
                    byte[] envelopeKey                  = context.EnvelopeKey;
                    byte[] iv                           = context.FirstIV;
                    byte[] encryptedEnvelopeKey         = EncryptionUtils.EncryptEnvelopeKey(envelopeKey, this.encryptionMaterials);
                    EncryptionInstructions instructions = new EncryptionInstructions(EncryptionMaterials.EmptyMaterialsDescription, envelopeKey, encryptedEnvelopeKey, iv);

                    PutObjectRequest instructionFileRequest = EncryptionUtils.CreateInstructionFileRequest(completeMultiPartUploadRequest, instructions);

                    S3ClientForInstructionFile.PutObject(instructionFileRequest);
                }

                //Clear Context data since encryption is completed
                currentMultiPartUploadKeys.Clear();
            }
        }
 protected abstract UnmarshallerContext ConstructUnmarshallerContext(
     Stream responseStream, bool maintainResponseBody, IWebResponseData response);
 public AmazonServiceException UnmarshallException(IWebResponseData response, ErrorResponse errorResponse, Exception innerException)
 {
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("AlreadyStreamed", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new AlreadyStreamedException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("DuplicateRequest", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new DuplicateRequestException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("InternalError", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new InternalErrorException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("InvalidParameter", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new InvalidParameterException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("NotAuthorizedError", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new NotAuthorizedException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("ResourceNotFound", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new ResourceNotFoundException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     return new AmazonCognitoSyncException(GetDefaultErrorMessage<AmazonCognitoSyncException>(), innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
 }
 /// <summary>
 /// Wrap an XmlTextReader with state for event-based parsing of an XML stream.
 /// </summary>
 /// <param name="responseStream"><c>Stream</c> with the XML from a service response.</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 S3UnmarshallerContext(Stream responseStream, bool maintainResponseBody, IWebResponseData responseData)
     : base(responseStream, maintainResponseBody, responseData)
 {
 }
Example #40
0
 public HttpErrorResponseException(IWebResponseData response)
 {
     this.Response = response;
 }
 public HttpErrorResponseException(string message, Exception innerException, IWebResponseData response) :
     base(message,innerException)
 {
     this.Response = response;
 }
Example #42
0
 public HttpErrorResponseException(string message, Exception innerException, IWebResponseData response)
     : base(message, innerException)
 {
     this.Response = response;
 }
 public AmazonServiceException UnmarshallException(IWebResponseData response, ErrorResponse errorResponse, Exception innerException)
 {
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("InternalError", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new InternalErrorException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("InvalidLambdaFunctionOutput", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new InvalidLambdaFunctionOutputException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("InvalidParameter", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new InvalidParameterException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("LambdaThrottled", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new LambdaThrottledException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("LimitExceeded", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new LimitExceededException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("NotAuthorizedError", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new NotAuthorizedException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("ResourceConflict", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new ResourceConflictException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("ResourceNotFound", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new ResourceNotFoundException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     if (!string.IsNullOrEmpty(errorResponse.Code) && errorResponse.Code.StartsWith("TooManyRequests", StringComparison.OrdinalIgnoreCase))
     {
         string message = string.IsNullOrEmpty(errorResponse.Message)?GetDefaultErrorMessage<AmazonCognitoSyncException>():errorResponse.Message;
         return new TooManyRequestsException(message, innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
     }
     return new AmazonCognitoSyncException(GetDefaultErrorMessage<AmazonCognitoSyncException>(), innerException, ErrorType.Unknown, errorResponse.Code, errorResponse.RequestId, response.StatusCode);
 }
        protected virtual void ProcessResponseHandlers(AmazonWebServiceResponse response, IRequest request, IWebResponseData webResponseData)
        {
            if (request == null)
            {
                return;
            }
            if (AfterResponseEvent == null)
            {
                return;
            }

            WebServiceResponseEventArgs args = WebServiceResponseEventArgs.Create(response, request, webResponseData);

            AfterResponseEvent(this, args);
        }
 /// <summary>
 /// Wrap an XmlTextReader with state for event-based parsing of an XML stream.
 /// </summary>
 /// <param name="responseStream"><c>Stream</c> with the XML from a service response.</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 XmlUnmarshallerContext(Stream responseStream, bool maintainResponseBody, IWebResponseData responseData)
 {
     if (maintainResponseBody)
     {
         this.WrappingStream = new CachingWrapperStream(responseStream);
         responseStream      = this.WrappingStream;
     }
     streamReader              = new StreamReader(responseStream);
     this.WebResponseData      = responseData;
     this.MaintainResponseBody = maintainResponseBody;
 }
Example #46
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);
        }
 protected override UnmarshallerContext ConstructUnmarshallerContext(Stream responseStream, bool maintainResponseBody, IWebResponseData response)
 {
     return new S3UnmarshallerContext(responseStream, maintainResponseBody, response);
 }
 /// <summary>
 /// Wrap an XmlTextReader with state for event-based parsing of an XML stream.
 /// </summary>
 /// <param name="responseStream"><c>Stream</c> with the XML from a service response.</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 S3UnmarshallerContext(Stream responseStream, bool maintainResponseBody, IWebResponseData responseData)
     : base(responseStream, maintainResponseBody, responseData)
 {
 }
Example #49
0
        private static void ProcessResponseHandlers(IExecutionContext executionContext)
        {
            AmazonWebServiceResponse response = executionContext.ResponseContext.Response;
            IRequest         request          = executionContext.RequestContext.Request;
            IWebResponseData webResponseData  = executionContext.ResponseContext.HttpResponse;
            bool             isSse            = HasSSEHeaders(webResponseData);

            var getObjectResponse = response as GetObjectResponse;

            if (getObjectResponse != null)
            {
                GetObjectRequest getObjectRequest = request.OriginalRequest as GetObjectRequest;
                getObjectResponse.BucketName = getObjectRequest.BucketName;
                getObjectResponse.Key        = getObjectRequest.Key;

                // If ETag is present and is an MD5 hash (not a multi-part upload ETag), and no byte range is specified,
                // wrap the response stream in an MD5Stream.
                // If there is a customer encryption algorithm the etag is not an MD5.
                if (!string.IsNullOrEmpty(getObjectResponse.ETag) &&
                    !getObjectResponse.ETag.Contains("-") &&
                    !isSse &&
                    getObjectRequest.ByteRange == null)
                {
                    string     etag         = getObjectResponse.ETag.Trim(etagTrimChars);
                    byte[]     expectedHash = AWSSDKUtils.HexStringToBytes(etag);
                    HashStream hashStream   = new MD5Stream(getObjectResponse.ResponseStream, expectedHash, getObjectResponse.ContentLength);
                    getObjectResponse.ResponseStream = hashStream;
                }
            }

            var deleteObjectsResponse = response as DeleteObjectsResponse;

            if (deleteObjectsResponse != null)
            {
                if (deleteObjectsResponse.DeleteErrors != null && deleteObjectsResponse.DeleteErrors.Count > 0)
                {
                    throw new DeleteObjectsException(deleteObjectsResponse as DeleteObjectsResponse);
                }
            }

            var putObjectResponse = response as PutObjectResponse;
            var putObjectRequest  = request.OriginalRequest as PutObjectRequest;

            if (putObjectRequest != null)
            {
                // If InputStream was a MD5Stream, compare calculated hash to returned etag
                MD5Stream hashStream = putObjectRequest.InputStream as MD5Stream;
                if (hashStream != null)
                {
                    if (putObjectResponse != null && !isSse)
                    {
                        // Stream may not have been closed, so force calculation of hash
                        hashStream.CalculateHash();
                        CompareHashes(putObjectResponse.ETag, hashStream.CalculatedHash);
                    }

                    // Set InputStream to its original value
                    putObjectRequest.InputStream = hashStream.GetNonWrapperBaseStream();
                }
            }

            var listObjectsResponse = response as ListObjectsResponse;

            if (listObjectsResponse != null)
            {
                if (listObjectsResponse.IsTruncated &&
                    string.IsNullOrEmpty(listObjectsResponse.NextMarker) &&
                    listObjectsResponse.S3Objects.Count > 0)
                {
                    listObjectsResponse.NextMarker = listObjectsResponse.S3Objects.Last().Key;
                }
            }

            var uploadPartRequest  = request.OriginalRequest as UploadPartRequest;
            var uploadPartResponse = response as UploadPartResponse;

            if (uploadPartRequest != null)
            {
                if (uploadPartResponse != null)
                {
                    uploadPartResponse.PartNumber = uploadPartRequest.PartNumber;
                }

                // If InputStream was a MD5Stream, compare calculated hash to returned etag
                MD5Stream hashStream = uploadPartRequest.InputStream as MD5Stream;
                if (hashStream != null)
                {
                    if (uploadPartResponse != null && !isSse)
                    {
                        // Stream may not have been closed, so force calculation of hash
                        hashStream.CalculateHash();
                        CompareHashes(uploadPartResponse.ETag, hashStream.CalculatedHash);
                    }

                    // Set InputStream to its original value
                    uploadPartRequest.InputStream = hashStream.GetNonWrapperBaseStream();
                }
            }

            var copyPartResponse = response as CopyPartResponse;

            if (copyPartResponse != null)
            {
                copyPartResponse.PartNumber = ((CopyPartRequest)request.OriginalRequest).PartNumber;
            }

            AmazonS3Client.CleanupRequest(request.OriginalRequest);
        }
 protected override UnmarshallerContext ConstructUnmarshallerContext(Stream responseStream, bool maintainResponseBody, IWebResponseData response, bool isException)
 {
     return(new S3UnmarshallerContext(responseStream, maintainResponseBody, response, isException));
 }