/// <exception cref="InvalidDataException"></exception> public IHttpResponse Deserialize(ResponseInfo responseInfo, Stream dataStream) { var contentType = responseInfo.GetHeaderValueOrNull(HttpHelper.ContentTypeHeader); if (string.IsNullOrWhiteSpace(contentType)) { throw new InvalidDataException("Content-Type header missed"); } var boundary = BatchSerializeHelper.GetBoundaryStringOrThrow(contentType); var subresponses = new List <IHttpResponse>(_subresponseDeserializers.Length); using (var reader = new PeekableStreamReader(dataStream)) { if (reader.ReadUntilFirstNonEmptyLine()) { while (true) { var subrequest = ParseNextSubresponseFrom(reader, boundary); subresponses.Add(subrequest); if (reader.PeekLine() == BatchSerializeHelper.GetCloseBoundaryString(boundary)) { break; } } } } if (subresponses.Count > _subresponseDeserializers.Length) { throw new InvalidDataException($"Actual and items count is greater than expected. Actual: {subresponses.Count}, expected: {_subresponseDeserializers.Length}"); } return(new HttpResponse <IHttpResponse[]>(responseInfo, subresponses.ToArray())); }
/// <exception cref="NotSupportedException"></exception> /// <exception cref="InvalidDataException"></exception> public IHttpResponse Deserialize(ResponseInfo responseInfo, Stream dataStream) { var contentType = responseInfo.GetHeaderValueOrNull(HttpHelper.ContentTypeHeader); return(GetSerializerFor(contentType) .Deserialize(responseInfo, dataStream)); }