@azure-typespec/http-client-csharp 1.0.0-alpha.20260821.3 → 1.0.0-alpha.20260821.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,9 +6,9 @@
6
6
  "compilationOptions": {},
7
7
  "targets": {
8
8
  ".NETCoreApp,Version=v10.0": {
9
- "Azure.Generator.StubLibrary/1.0.0-alpha.20260821.3": {
9
+ "Azure.Generator.StubLibrary/1.0.0-alpha.20260821.4": {
10
10
  "dependencies": {
11
- "Azure.Generator": "1.0.0-alpha.20260821.3",
11
+ "Azure.Generator": "1.0.0-alpha.20260821.4",
12
12
  "Microsoft.TypeSpec.Generator.ClientModel": "1.0.0-alpha.20260821.2",
13
13
  "System.ClientModel": "1.15.0"
14
14
  },
@@ -711,7 +711,7 @@
711
711
  }
712
712
  }
713
713
  },
714
- "Azure.Generator/1.0.0-alpha.20260821.3": {
714
+ "Azure.Generator/1.0.0-alpha.20260821.4": {
715
715
  "dependencies": {
716
716
  "Azure.Core": "1.62.0",
717
717
  "Azure.Core.Expressions.DataFactory": "1.0.0",
@@ -721,14 +721,14 @@
721
721
  "runtime": {
722
722
  "Azure.Generator.dll": {
723
723
  "assemblyVersion": "1.0.0.0",
724
- "fileVersion": "1.0.26.42103"
724
+ "fileVersion": "1.0.26.42104"
725
725
  }
726
726
  }
727
727
  }
728
728
  }
729
729
  },
730
730
  "libraries": {
731
- "Azure.Generator.StubLibrary/1.0.0-alpha.20260821.3": {
731
+ "Azure.Generator.StubLibrary/1.0.0-alpha.20260821.4": {
732
732
  "type": "project",
733
733
  "serviceable": false,
734
734
  "sha512": ""
@@ -1069,7 +1069,7 @@
1069
1069
  "path": "system.security.cryptography.protecteddata/8.0.0",
1070
1070
  "hashPath": "system.security.cryptography.protecteddata.8.0.0.nupkg.sha512"
1071
1071
  },
1072
- "Azure.Generator/1.0.0-alpha.20260821.3": {
1072
+ "Azure.Generator/1.0.0-alpha.20260821.4": {
1073
1073
  "type": "project",
1074
1074
  "serviceable": false,
1075
1075
  "sha512": ""
@@ -6,7 +6,7 @@
6
6
  "compilationOptions": {},
7
7
  "targets": {
8
8
  ".NETCoreApp,Version=v10.0": {
9
- "Azure.Generator/1.0.0-alpha.20260821.3": {
9
+ "Azure.Generator/1.0.0-alpha.20260821.4": {
10
10
  "dependencies": {
11
11
  "Azure.Core": "1.62.0",
12
12
  "Azure.Core.Expressions.DataFactory": "1.0.0",
@@ -715,7 +715,7 @@
715
715
  }
716
716
  },
717
717
  "libraries": {
718
- "Azure.Generator/1.0.0-alpha.20260821.3": {
718
+ "Azure.Generator/1.0.0-alpha.20260821.4": {
719
719
  "type": "project",
720
720
  "serviceable": false,
721
721
  "sha512": ""
Binary file
Binary file
@@ -14,32 +14,55 @@ namespace Azure.Core
14
14
  {
15
15
  internal sealed class AzurePipelineResponse : PipelineResponse
16
16
  {
17
- private readonly Response _response;
18
17
  private readonly PipelineResponseHeaders _headers;
18
+ private readonly int _status;
19
+ private readonly string _reasonPhrase;
20
+ private Stream? _contentStream;
19
21
 
20
- internal AzurePipelineResponse(Response response)
22
+ internal AzurePipelineResponse(HttpMessage message)
21
23
  {
22
- _response = response;
24
+ Response response = message.Response;
23
25
  _headers = new AzurePipelineResponseHeaders(response.Headers);
26
+ _status = response.Status;
27
+ _reasonPhrase = response.ReasonPhrase;
28
+ _contentStream = message.ExtractResponseContent();
24
29
  }
25
30
 
26
- public override int Status => _response.Status;
31
+ public override int Status => _status;
27
32
 
28
- public override string ReasonPhrase => _response.ReasonPhrase;
33
+ public override string ReasonPhrase => _reasonPhrase;
29
34
 
30
35
  protected override PipelineResponseHeaders HeadersCore => _headers;
31
36
 
32
37
  public override Stream? ContentStream
33
38
  {
34
- get => _response.ContentStream;
35
- set => _response.ContentStream = value;
39
+ get => _contentStream;
40
+ set => _contentStream = value;
36
41
  }
37
42
 
38
- public override BinaryData Content => _response.Content;
43
+ public override BinaryData Content
44
+ {
45
+ get
46
+ {
47
+ if (_contentStream is null)
48
+ {
49
+ return BinaryData.Empty;
50
+ }
51
+
52
+ if (_contentStream is not MemoryStream content)
53
+ {
54
+ throw new InvalidOperationException("The response is not buffered.");
55
+ }
56
+
57
+ return content.TryGetBuffer(out ArraySegment<byte> segment)
58
+ ? new BinaryData(segment.AsMemory())
59
+ : new BinaryData(content.ToArray());
60
+ }
61
+ }
39
62
 
40
63
  public override BinaryData BufferContent(CancellationToken cancellationToken = default)
41
64
  {
42
- Stream? responseContentStream = _response.ContentStream;
65
+ Stream? responseContentStream = ContentStream;
43
66
  if (responseContentStream is not MemoryStream)
44
67
  {
45
68
  var content = new MemoryStream();
@@ -51,7 +74,7 @@ namespace Azure.Core
51
74
  }
52
75
  content.Position = 0;
53
76
  responseContentStream?.Dispose();
54
- _response.ContentStream = content;
77
+ ContentStream = content;
55
78
  }
56
79
  catch
57
80
  {
@@ -60,12 +83,12 @@ namespace Azure.Core
60
83
  }
61
84
  }
62
85
 
63
- return _response.Content;
86
+ return Content;
64
87
  }
65
88
 
66
89
  public override async ValueTask<BinaryData> BufferContentAsync(CancellationToken cancellationToken = default)
67
90
  {
68
- Stream? responseContentStream = _response.ContentStream;
91
+ Stream? responseContentStream = ContentStream;
69
92
  if (responseContentStream is not MemoryStream)
70
93
  {
71
94
  var content = new MemoryStream();
@@ -77,7 +100,7 @@ namespace Azure.Core
77
100
  }
78
101
  content.Position = 0;
79
102
  responseContentStream?.Dispose();
80
- _response.ContentStream = content;
103
+ ContentStream = content;
81
104
  }
82
105
  catch
83
106
  {
@@ -86,10 +109,14 @@ namespace Azure.Core
86
109
  }
87
110
  }
88
111
 
89
- return _response.Content;
112
+ return Content;
90
113
  }
91
114
 
92
- public override void Dispose() => _response.Dispose();
115
+ public override void Dispose()
116
+ {
117
+ _contentStream?.Dispose();
118
+ _contentStream = null;
119
+ }
93
120
 
94
121
  private static void CopyTo(Stream source, Stream destination, CancellationToken cancellationToken)
95
122
  {
@@ -109,24 +136,41 @@ namespace Azure.Core
109
136
 
110
137
  private sealed class AzurePipelineResponseHeaders : PipelineResponseHeaders
111
138
  {
112
- private readonly ResponseHeaders _headers;
139
+ private readonly Dictionary<string, string> _headerValues;
140
+ private readonly Dictionary<string, IEnumerable<string>> _headerValueCollections;
141
+ private readonly List<KeyValuePair<string, string>> _headerList;
113
142
 
114
143
  internal AzurePipelineResponseHeaders(ResponseHeaders headers)
115
144
  {
116
- _headers = headers;
145
+ _headerValues = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
146
+ _headerValueCollections = new Dictionary<string, IEnumerable<string>>(StringComparer.OrdinalIgnoreCase);
147
+ _headerList = new List<KeyValuePair<string, string>>();
148
+ foreach (HttpHeader header in headers)
149
+ {
150
+ if (!_headerValues.ContainsKey(header.Name))
151
+ {
152
+ _headerValues.Add(header.Name, header.Value);
153
+ }
154
+ if (!_headerValueCollections.ContainsKey(header.Name)
155
+ && headers.TryGetValues(header.Name, out IEnumerable<string>? values))
156
+ {
157
+ _headerValueCollections.Add(header.Name, new List<string>(values));
158
+ }
159
+ _headerList.Add(new KeyValuePair<string, string>(header.Name, header.Value));
160
+ }
117
161
  }
118
162
 
119
163
  public override bool TryGetValue(string name, out string? value)
120
- => _headers.TryGetValue(name, out value);
164
+ => _headerValues.TryGetValue(name, out value);
121
165
 
122
166
  public override bool TryGetValues(string name, out IEnumerable<string>? values)
123
- => _headers.TryGetValues(name, out values);
167
+ => _headerValueCollections.TryGetValue(name, out values);
124
168
 
125
169
  public override IEnumerator<KeyValuePair<string, string>> GetEnumerator()
126
170
  {
127
- foreach (HttpHeader header in _headers)
171
+ foreach (KeyValuePair<string, string> header in _headerList)
128
172
  {
129
- yield return new KeyValuePair<string, string>(header.Name, header.Value);
173
+ yield return header;
130
174
  }
131
175
  }
132
176
  }
@@ -6,9 +6,9 @@
6
6
  "compilationOptions": {},
7
7
  "targets": {
8
8
  ".NETCoreApp,Version=v10.0": {
9
- "Azure.Generator.StubLibrary/1.0.0-alpha.20260821.3": {
9
+ "Azure.Generator.StubLibrary/1.0.0-alpha.20260821.4": {
10
10
  "dependencies": {
11
- "Azure.Generator": "1.0.0-alpha.20260821.3",
11
+ "Azure.Generator": "1.0.0-alpha.20260821.4",
12
12
  "Microsoft.TypeSpec.Generator.ClientModel": "1.0.0-alpha.20260821.2",
13
13
  "System.ClientModel": "1.15.0"
14
14
  },
@@ -711,7 +711,7 @@
711
711
  }
712
712
  }
713
713
  },
714
- "Azure.Generator/1.0.0-alpha.20260821.3": {
714
+ "Azure.Generator/1.0.0-alpha.20260821.4": {
715
715
  "dependencies": {
716
716
  "Azure.Core": "1.62.0",
717
717
  "Azure.Core.Expressions.DataFactory": "1.0.0",
@@ -721,14 +721,14 @@
721
721
  "runtime": {
722
722
  "Azure.Generator.dll": {
723
723
  "assemblyVersion": "1.0.0.0",
724
- "fileVersion": "1.0.26.42103"
724
+ "fileVersion": "1.0.26.42104"
725
725
  }
726
726
  }
727
727
  }
728
728
  }
729
729
  },
730
730
  "libraries": {
731
- "Azure.Generator.StubLibrary/1.0.0-alpha.20260821.3": {
731
+ "Azure.Generator.StubLibrary/1.0.0-alpha.20260821.4": {
732
732
  "type": "project",
733
733
  "serviceable": false,
734
734
  "sha512": ""
@@ -1069,7 +1069,7 @@
1069
1069
  "path": "system.security.cryptography.protecteddata/8.0.0",
1070
1070
  "hashPath": "system.security.cryptography.protecteddata.8.0.0.nupkg.sha512"
1071
1071
  },
1072
- "Azure.Generator/1.0.0-alpha.20260821.3": {
1072
+ "Azure.Generator/1.0.0-alpha.20260821.4": {
1073
1073
  "type": "project",
1074
1074
  "serviceable": false,
1075
1075
  "sha512": ""
@@ -6,7 +6,7 @@
6
6
  "compilationOptions": {},
7
7
  "targets": {
8
8
  ".NETCoreApp,Version=v10.0": {
9
- "Azure.Generator/1.0.0-alpha.20260821.3": {
9
+ "Azure.Generator/1.0.0-alpha.20260821.4": {
10
10
  "dependencies": {
11
11
  "Azure.Core": "1.62.0",
12
12
  "Azure.Core.Expressions.DataFactory": "1.0.0",
@@ -715,7 +715,7 @@
715
715
  }
716
716
  },
717
717
  "libraries": {
718
- "Azure.Generator/1.0.0-alpha.20260821.3": {
718
+ "Azure.Generator/1.0.0-alpha.20260821.4": {
719
719
  "type": "project",
720
720
  "serviceable": false,
721
721
  "sha512": ""
@@ -14,32 +14,55 @@ namespace Azure.Core
14
14
  {
15
15
  internal sealed class AzurePipelineResponse : PipelineResponse
16
16
  {
17
- private readonly Response _response;
18
17
  private readonly PipelineResponseHeaders _headers;
18
+ private readonly int _status;
19
+ private readonly string _reasonPhrase;
20
+ private Stream? _contentStream;
19
21
 
20
- internal AzurePipelineResponse(Response response)
22
+ internal AzurePipelineResponse(HttpMessage message)
21
23
  {
22
- _response = response;
24
+ Response response = message.Response;
23
25
  _headers = new AzurePipelineResponseHeaders(response.Headers);
26
+ _status = response.Status;
27
+ _reasonPhrase = response.ReasonPhrase;
28
+ _contentStream = message.ExtractResponseContent();
24
29
  }
25
30
 
26
- public override int Status => _response.Status;
31
+ public override int Status => _status;
27
32
 
28
- public override string ReasonPhrase => _response.ReasonPhrase;
33
+ public override string ReasonPhrase => _reasonPhrase;
29
34
 
30
35
  protected override PipelineResponseHeaders HeadersCore => _headers;
31
36
 
32
37
  public override Stream? ContentStream
33
38
  {
34
- get => _response.ContentStream;
35
- set => _response.ContentStream = value;
39
+ get => _contentStream;
40
+ set => _contentStream = value;
36
41
  }
37
42
 
38
- public override BinaryData Content => _response.Content;
43
+ public override BinaryData Content
44
+ {
45
+ get
46
+ {
47
+ if (_contentStream is null)
48
+ {
49
+ return BinaryData.Empty;
50
+ }
51
+
52
+ if (_contentStream is not MemoryStream content)
53
+ {
54
+ throw new InvalidOperationException("The response is not buffered.");
55
+ }
56
+
57
+ return content.TryGetBuffer(out ArraySegment<byte> segment)
58
+ ? new BinaryData(segment.AsMemory())
59
+ : new BinaryData(content.ToArray());
60
+ }
61
+ }
39
62
 
40
63
  public override BinaryData BufferContent(CancellationToken cancellationToken = default)
41
64
  {
42
- Stream? responseContentStream = _response.ContentStream;
65
+ Stream? responseContentStream = ContentStream;
43
66
  if (responseContentStream is not MemoryStream)
44
67
  {
45
68
  var content = new MemoryStream();
@@ -51,7 +74,7 @@ namespace Azure.Core
51
74
  }
52
75
  content.Position = 0;
53
76
  responseContentStream?.Dispose();
54
- _response.ContentStream = content;
77
+ ContentStream = content;
55
78
  }
56
79
  catch
57
80
  {
@@ -60,12 +83,12 @@ namespace Azure.Core
60
83
  }
61
84
  }
62
85
 
63
- return _response.Content;
86
+ return Content;
64
87
  }
65
88
 
66
89
  public override async ValueTask<BinaryData> BufferContentAsync(CancellationToken cancellationToken = default)
67
90
  {
68
- Stream? responseContentStream = _response.ContentStream;
91
+ Stream? responseContentStream = ContentStream;
69
92
  if (responseContentStream is not MemoryStream)
70
93
  {
71
94
  var content = new MemoryStream();
@@ -77,7 +100,7 @@ namespace Azure.Core
77
100
  }
78
101
  content.Position = 0;
79
102
  responseContentStream?.Dispose();
80
- _response.ContentStream = content;
103
+ ContentStream = content;
81
104
  }
82
105
  catch
83
106
  {
@@ -86,10 +109,14 @@ namespace Azure.Core
86
109
  }
87
110
  }
88
111
 
89
- return _response.Content;
112
+ return Content;
90
113
  }
91
114
 
92
- public override void Dispose() => _response.Dispose();
115
+ public override void Dispose()
116
+ {
117
+ _contentStream?.Dispose();
118
+ _contentStream = null;
119
+ }
93
120
 
94
121
  private static void CopyTo(Stream source, Stream destination, CancellationToken cancellationToken)
95
122
  {
@@ -109,24 +136,41 @@ namespace Azure.Core
109
136
 
110
137
  private sealed class AzurePipelineResponseHeaders : PipelineResponseHeaders
111
138
  {
112
- private readonly ResponseHeaders _headers;
139
+ private readonly Dictionary<string, string> _headerValues;
140
+ private readonly Dictionary<string, IEnumerable<string>> _headerValueCollections;
141
+ private readonly List<KeyValuePair<string, string>> _headerList;
113
142
 
114
143
  internal AzurePipelineResponseHeaders(ResponseHeaders headers)
115
144
  {
116
- _headers = headers;
145
+ _headerValues = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
146
+ _headerValueCollections = new Dictionary<string, IEnumerable<string>>(StringComparer.OrdinalIgnoreCase);
147
+ _headerList = new List<KeyValuePair<string, string>>();
148
+ foreach (HttpHeader header in headers)
149
+ {
150
+ if (!_headerValues.ContainsKey(header.Name))
151
+ {
152
+ _headerValues.Add(header.Name, header.Value);
153
+ }
154
+ if (!_headerValueCollections.ContainsKey(header.Name)
155
+ && headers.TryGetValues(header.Name, out IEnumerable<string>? values))
156
+ {
157
+ _headerValueCollections.Add(header.Name, new List<string>(values));
158
+ }
159
+ _headerList.Add(new KeyValuePair<string, string>(header.Name, header.Value));
160
+ }
117
161
  }
118
162
 
119
163
  public override bool TryGetValue(string name, out string? value)
120
- => _headers.TryGetValue(name, out value);
164
+ => _headerValues.TryGetValue(name, out value);
121
165
 
122
166
  public override bool TryGetValues(string name, out IEnumerable<string>? values)
123
- => _headers.TryGetValues(name, out values);
167
+ => _headerValueCollections.TryGetValue(name, out values);
124
168
 
125
169
  public override IEnumerator<KeyValuePair<string, string>> GetEnumerator()
126
170
  {
127
- foreach (HttpHeader header in _headers)
171
+ foreach (KeyValuePair<string, string> header in _headerList)
128
172
  {
129
- yield return new KeyValuePair<string, string>(header.Name, header.Value);
173
+ yield return header;
130
174
  }
131
175
  }
132
176
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-typespec/http-client-csharp",
3
- "version": "1.0.0-alpha.20260821.3",
3
+ "version": "1.0.0-alpha.20260821.4",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec library for emitting Azure libraries for C#.",
6
6
  "readme": "https://github.com/Azure/azure-sdk-for-net/blob/main/eng/packages/http-client-csharp/README.md",