| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | namespace System.Net.Http |
| | | 5 | | { |
| | | 6 | | internal abstract class HttpContentStream : HttpBaseStream |
| | | 7 | | { |
| | | 8 | | protected internal HttpConnection? _connection; |
| | | 9 | | |
| | 0 | 10 | | public HttpContentStream(HttpConnection connection) |
| | 0 | 11 | | { |
| | 0 | 12 | | _connection = connection; |
| | 0 | 13 | | } |
| | | 14 | | |
| | | 15 | | public override void Write(byte[] buffer, int offset, int count) |
| | 0 | 16 | | { |
| | 0 | 17 | | ValidateBufferArguments(buffer, offset, count); |
| | 0 | 18 | | Write(new ReadOnlySpan<byte>(buffer, offset, count)); |
| | 0 | 19 | | } |
| | | 20 | | |
| | | 21 | | protected override void Dispose(bool disposing) |
| | 0 | 22 | | { |
| | 0 | 23 | | if (disposing) |
| | 0 | 24 | | { |
| | 0 | 25 | | if (_connection != null) |
| | 0 | 26 | | { |
| | 0 | 27 | | _connection.Dispose(); |
| | 0 | 28 | | _connection = null; |
| | 0 | 29 | | } |
| | 0 | 30 | | } |
| | | 31 | | |
| | 0 | 32 | | base.Dispose(disposing); |
| | 0 | 33 | | } |
| | | 34 | | |
| | | 35 | | protected HttpConnection GetConnectionOrThrow() |
| | 0 | 36 | | { |
| | 0 | 37 | | HttpConnection? c = _connection; |
| | | 38 | | |
| | | 39 | | // Disposal should only ever happen if the user-code that was handed this instance disposed of |
| | | 40 | | // it, which is misuse, or held onto it and tried to use it later after we've disposed of it, |
| | | 41 | | // which is also misuse. |
| | 0 | 42 | | ObjectDisposedException.ThrowIf(c is null, this); |
| | | 43 | | |
| | 0 | 44 | | return c; |
| | 0 | 45 | | } |
| | | 46 | | } |
| | | 47 | | } |