Skip to content

Commit 53a5a5b

Browse files
committed
fix(WebManager): 修复Transfer-Encoding存在时设置内存流长度的问题
当响应头包含Transfer-Encoding时,不应预设内存流长度,以避免内容长度不匹配导致的异常。
1 parent 4003fc2 commit 53a5a5b

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

Runtime/Web/WebManager.Binary.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,16 @@ private async void MakeBinaryBytesRequest(WebBinaryData webData)
151151
{
152152
using (Stream responseStream = response.GetResponseStream())
153153
{
154-
m_MemoryStream.SetLength(response.ContentLength);
154+
var transferEncoding = response.Headers.Get("Transfer-Encoding");
155+
if (string.IsNullOrWhiteSpace(transferEncoding))
156+
{
157+
m_MemoryStream.SetLength(response.ContentLength);
158+
}
159+
155160
m_MemoryStream.Position = 0;
156161
await responseStream.CopyToAsync(m_MemoryStream);
157-
webData.Task.SetResult(new WebBufferResult(webData.UserData, m_MemoryStream.ToArray())); // 将流的内容复制到内存流中并转换为byte数组
162+
var resultData = m_MemoryStream.ToArray();
163+
webData.Task.SetResult(new WebBufferResult(webData.UserData, resultData)); // 将流的内容复制到内存流中并转换为byte数组
158164
}
159165
}
160166
}

0 commit comments

Comments
 (0)