You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
@ -37,6 +37,8 @@ namespace System.Net.Http
|
||||
readonly Stream content;
|
||||
readonly int bufferSize;
|
||||
readonly CancellationToken cancellationToken;
|
||||
readonly long startPosition;
|
||||
bool contentCopied;
|
||||
|
||||
public StreamContent (Stream content)
|
||||
: this (content, 16 * 1024)
|
||||
@ -53,6 +55,10 @@ namespace System.Net.Http
|
||||
|
||||
this.content = content;
|
||||
this.bufferSize = bufferSize;
|
||||
|
||||
if (content.CanSeek) {
|
||||
startPosition = content.Position;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@ -83,6 +89,16 @@ namespace System.Net.Http
|
||||
|
||||
protected internal override Task SerializeToStreamAsync (Stream stream, TransportContext context)
|
||||
{
|
||||
if (contentCopied) {
|
||||
if (!content.CanSeek) {
|
||||
throw new InvalidOperationException ("The stream was already consumed. It cannot be read again.");
|
||||
}
|
||||
|
||||
content.Seek (startPosition, SeekOrigin.Begin);
|
||||
} else {
|
||||
contentCopied = true;
|
||||
}
|
||||
|
||||
return content.CopyToAsync (stream, bufferSize, cancellationToken);
|
||||
}
|
||||
|
||||
@ -92,7 +108,7 @@ namespace System.Net.Http
|
||||
length = 0;
|
||||
return false;
|
||||
}
|
||||
length = content.Length;
|
||||
length = content.Length - startPosition;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -101,6 +101,12 @@ namespace MonoTests.System.Net.Http.Headers
|
||||
Assert.IsNull (res.To, "#22");
|
||||
Assert.IsNull (res.Length, "#23");
|
||||
Assert.AreEqual ("by */*", res.ToString (), "#24");
|
||||
|
||||
res = ContentRangeHeaderValue.Parse("bytes 199999999999999999 - 999999999999999999/ 9223372036854775807");
|
||||
Assert.AreEqual (199999999999999999, res.From, "#31");
|
||||
Assert.AreEqual (999999999999999999, res.To, "#32");
|
||||
Assert.AreEqual (9223372036854775807, res.Length, "#33");
|
||||
Assert.AreEqual ("bytes 199999999999999999-999999999999999999/9223372036854775807", res.ToString (), "#34");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -149,8 +149,8 @@ namespace MonoTests.System.Net.Http
|
||||
/*
|
||||
sc = new StreamContent (new ExceptionStream ());
|
||||
try {
|
||||
sc.CopyToAsync (m).Wait ();
|
||||
Assert.Fail ("#2");
|
||||
sc.CopyToAsync (m).Wait ();
|
||||
Assert.Fail ("#2");
|
||||
} catch (AggregateException) {
|
||||
}
|
||||
*/
|
||||
@ -190,6 +190,32 @@ namespace MonoTests.System.Net.Http
|
||||
Assert.IsTrue (hit, "#10");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CopyToAsync_Twice ()
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
ms.WriteByte(4);
|
||||
ms.WriteByte(12);
|
||||
ms.WriteByte(7);
|
||||
ms.Seek(1, SeekOrigin.Begin);
|
||||
|
||||
var sc = new StreamContent(ms);
|
||||
|
||||
var dest = new MemoryStream();
|
||||
var task = sc.CopyToAsync(dest);
|
||||
Assert.True(task.Wait(3000), "#0");
|
||||
Assert.AreEqual(2, dest.Length, "#1");
|
||||
dest.Seek(0, SeekOrigin.Begin);
|
||||
Assert.AreEqual(12, dest.ReadByte(), "#2");
|
||||
|
||||
dest = new MemoryStream();
|
||||
task = sc.CopyToAsync(dest);
|
||||
Assert.True(task.Wait(3000), "#10");
|
||||
Assert.AreEqual(2, dest.Length, "#11");
|
||||
dest.Seek(0, SeekOrigin.Begin);
|
||||
Assert.AreEqual(12, dest.ReadByte(), "#12");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CopyToAsync_ClosedInput ()
|
||||
{
|
||||
|
Reference in New Issue
Block a user