|
8 | 8 | namespace Elastic.Transport;
|
9 | 9 |
|
10 | 10 | /// <summary>
|
11 |
| -/// A response that exposes the response <see cref="TransportResponse{T}.Body"/> as <see cref="Stream"/>. |
| 11 | +/// A response that exposes the response as a <see cref="Stream"/>. |
12 | 12 | /// <para>
|
13 | 13 | /// <strong>MUST</strong> be disposed after use to ensure the HTTP connection is freed for reuse.
|
14 | 14 | /// </para>
|
15 | 15 | /// </summary>
|
16 |
| -public class StreamResponse : TransportResponse<Stream>, IDisposable |
| 16 | +public sealed class StreamResponse : StreamResponseBase, IDisposable |
17 | 17 | {
|
18 |
| - private bool _disposed; |
19 |
| - |
20 |
| - /// <summary> |
21 |
| - /// The MIME type of the response, if present. |
22 |
| - /// </summary> |
23 |
| - public string ContentType { get; } |
24 |
| - |
25 | 18 | /// <inheritdoc cref="StreamResponse"/>
|
26 |
| - public StreamResponse() |
27 |
| - { |
28 |
| - Body = Stream.Null; |
| 19 | + public StreamResponse() : base(Stream.Null) => |
29 | 20 | ContentType = string.Empty;
|
30 |
| - } |
31 | 21 |
|
32 | 22 | /// <inheritdoc cref="StreamResponse"/>
|
33 |
| - public StreamResponse(Stream body, string? contentType) |
34 |
| - { |
35 |
| - Body = body; |
| 23 | + public StreamResponse(Stream body, string? contentType) : base(body) => |
36 | 24 | ContentType = contentType ?? string.Empty;
|
37 |
| - } |
38 |
| - |
39 |
| - internal override bool LeaveOpen => true; |
40 | 25 |
|
41 | 26 | /// <summary>
|
42 |
| - /// Disposes the underlying stream. |
| 27 | + /// The MIME type of the response, if present. |
43 | 28 | /// </summary>
|
44 |
| - /// <param name="disposing"></param> |
45 |
| - protected virtual void Dispose(bool disposing) |
46 |
| - { |
47 |
| - if (!_disposed) |
48 |
| - { |
49 |
| - if (disposing) |
50 |
| - { |
51 |
| - Body.Dispose(); |
52 |
| - |
53 |
| - if (LinkedDisposables is not null) |
54 |
| - { |
55 |
| - foreach (var disposable in LinkedDisposables) |
56 |
| - disposable.Dispose(); |
57 |
| - } |
58 |
| - } |
59 |
| - |
60 |
| - _disposed = true; |
61 |
| - } |
62 |
| - } |
| 29 | + public string ContentType { get; } |
63 | 30 |
|
64 | 31 | /// <summary>
|
65 |
| - /// Disposes the underlying stream. |
| 32 | + /// The raw response stream. |
66 | 33 | /// </summary>
|
67 |
| - public void Dispose() |
68 |
| - { |
69 |
| - Dispose(disposing: true); |
70 |
| - GC.SuppressFinalize(this); |
71 |
| - } |
| 34 | + public Stream Body => Stream; |
| 35 | + |
| 36 | + /// <inheritdoc/> |
| 37 | + protected internal override bool LeaveOpen => true; |
72 | 38 | }
|
0 commit comments