-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy stream for upload requests and remove expect header (#739)
Co-authored-by: Marcin Hagmajer <[email protected]>
- Loading branch information
Showing
4 changed files
with
81 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.IO; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
namespace Box.V2.Request | ||
{ | ||
class ReusableContent : HttpContent | ||
{ | ||
private Stream _innerContent; | ||
private long _contentLength; | ||
|
||
public ReusableContent(Stream stream) | ||
{ | ||
_innerContent = stream; | ||
_contentLength = stream.Length; | ||
} | ||
|
||
protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context) | ||
{ | ||
_innerContent.Position = 0; | ||
await _innerContent.CopyToAsync(stream); | ||
} | ||
|
||
protected override bool TryComputeLength(out long length) | ||
{ | ||
length = _contentLength; | ||
return true; | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
// Don't call dispose on stream content as it will close the base stream. | ||
_innerContent = null; | ||
base.Dispose(disposing); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters