/// <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); 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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }