@@ -12,6 +12,9 @@ namespace System.Net.Http
12
12
{
13
13
internal static partial class X509ResourceClient
14
14
{
15
+ private const long DefaultAiaDownloadLimit = 100 * 1024 * 1024 ;
16
+
17
+ private static long AiaDownloadLimit { get ; } = GetValue ( "System.Security.Cryptography.AiaDownloadLimit" , DefaultAiaDownloadLimit ) ;
15
18
private static readonly Func < string , CancellationToken , bool , ValueTask < byte [ ] ? > > ? s_downloadBytes = CreateDownloadBytesFunc ( ) ;
16
19
17
20
static partial void ReportNoClient ( ) ;
@@ -115,6 +118,7 @@ internal static partial class X509ResourceClient
115
118
ConstructorInfo ? httpRequestMessageCtor = httpRequestMessageType . GetConstructor ( Type . EmptyTypes ) ;
116
119
MethodInfo ? sendMethod = httpClientType . GetMethod ( "Send" , new Type [ ] { httpRequestMessageType , typeof ( CancellationToken ) } ) ;
117
120
MethodInfo ? sendAsyncMethod = httpClientType . GetMethod ( "SendAsync" , new Type [ ] { httpRequestMessageType , typeof ( CancellationToken ) } ) ;
121
+ PropertyInfo ? maxResponseContentBufferSizeProp = httpClientType . GetProperty ( "MaxResponseContentBufferSize" ) ;
118
122
PropertyInfo ? responseContentProp = httpResponseMessageType . GetProperty ( "Content" ) ;
119
123
PropertyInfo ? responseStatusCodeProp = httpResponseMessageType . GetProperty ( "StatusCode" ) ;
120
124
PropertyInfo ? responseHeadersProp = httpResponseMessageType . GetProperty ( "Headers" ) ;
@@ -125,7 +129,7 @@ internal static partial class X509ResourceClient
125
129
if ( socketsHttpHandlerCtor == null || pooledConnectionIdleTimeoutProp == null ||
126
130
allowAutoRedirectProp == null || httpClientCtor == null ||
127
131
requestUriProp == null || httpRequestMessageCtor == null ||
128
- sendMethod == null || sendAsyncMethod == null ||
132
+ sendMethod == null || sendAsyncMethod == null || maxResponseContentBufferSizeProp == null ||
129
133
responseContentProp == null || responseStatusCodeProp == null ||
130
134
responseHeadersProp == null || responseHeadersLocationProp == null ||
131
135
readAsStreamMethod == null || taskOfHttpResponseMessageResultProp == null )
@@ -149,6 +153,7 @@ internal static partial class X509ResourceClient
149
153
pooledConnectionIdleTimeoutProp . SetValue ( socketsHttpHandler , TimeSpan . FromSeconds ( PooledConnectionIdleTimeoutSeconds ) ) ;
150
154
allowAutoRedirectProp . SetValue ( socketsHttpHandler , false ) ;
151
155
object ? httpClient = httpClientCtor . Invoke ( new object ? [ ] { socketsHttpHandler } ) ;
156
+ maxResponseContentBufferSizeProp . SetValue ( httpClient , AiaDownloadLimit ) ;
152
157
153
158
return async ( string uriString , CancellationToken cancellationToken , bool async ) =>
154
159
{
@@ -306,5 +311,24 @@ private static bool IsAllowedScheme(string scheme)
306
311
{
307
312
return string . Equals( scheme , "http ", StringComparison . OrdinalIgnoreCase ) ;
308
313
}
314
+
315
+ private static long GetValue ( string name , long defaultValue )
316
+ {
317
+ object ? data = AppContext. GetData( name ) ;
318
+
319
+ if ( data is null)
320
+ {
321
+ return defaultValue;
322
+ }
323
+
324
+ try
325
+ {
326
+ return Convert. ToInt64( data) ;
327
+ }
328
+ catch
329
+ {
330
+ return defaultValue;
331
+ }
332
+ }
309
333
}
310
334
}
0 commit comments