Skip to content

Commit e05400f

Browse files
committed
Fixes #47
Workaround for dotnet/corefx#9071
1 parent 59a07bf commit e05400f

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/FubarDev.WebDavServer/Handlers/Impl/GetResults/WebDavFullDocumentResult.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,23 @@ public override async Task ExecuteResultAsync(IWebDavResponse response, Cancella
6969

7070
using (var stream = await _document.OpenReadAsync(ct).ConfigureAwait(false))
7171
{
72-
var content = new StreamContent(stream);
73-
await SetPropertiesToContentHeaderAsync(content, properties, ct).ConfigureAwait(false);
74-
75-
foreach (var header in content.Headers)
72+
using (var content = new StreamContent(stream))
7673
{
77-
response.Headers.Add(header.Key, header.Value.ToArray());
74+
// I'm storing the headers in the content, because I'm too lazy to
75+
// look up the header names and the formatting of its values.
76+
await SetPropertiesToContentHeaderAsync(content, properties, ct).ConfigureAwait(false);
77+
78+
foreach (var header in content.Headers)
79+
{
80+
response.Headers.Add(header.Key, header.Value.ToArray());
81+
}
82+
83+
// Use the CopyToAsync function of the stream itself, because
84+
// we're able to pass the cancellation token. This is a workaround
85+
// for issue dotnet/corefx#9071 and fixes FubarDevelopment/WebDavServer#47.
86+
await stream.CopyToAsync(response.Body, 81920, ct)
87+
.ConfigureAwait(false);
7888
}
79-
80-
await content.CopyToAsync(response.Body).ConfigureAwait(false);
8189
}
8290
}
8391

0 commit comments

Comments
 (0)