@@ -12,6 +12,9 @@ namespace System.Net.Http
1212{
1313 internal static partial class X509ResourceClient
1414 {
15+ private const long DefaultAiaDownloadLimit = 100 * 1024 * 1024 ;
16+
17+ private static long AiaDownloadLimit { get ; } = GetValue ( "System.Security.Cryptography.AiaDownloadLimit" , DefaultAiaDownloadLimit ) ;
1518 private static readonly Func < string , CancellationToken , bool , ValueTask < byte [ ] ? > > ? s_downloadBytes = CreateDownloadBytesFunc ( ) ;
1619
1720 static partial void ReportNoClient ( ) ;
@@ -115,6 +118,7 @@ internal static partial class X509ResourceClient
115118 ConstructorInfo ? httpRequestMessageCtor = httpRequestMessageType . GetConstructor ( Type . EmptyTypes ) ;
116119 MethodInfo ? sendMethod = httpClientType . GetMethod ( "Send" , new Type [ ] { httpRequestMessageType , typeof ( CancellationToken ) } ) ;
117120 MethodInfo ? sendAsyncMethod = httpClientType . GetMethod ( "SendAsync" , new Type [ ] { httpRequestMessageType , typeof ( CancellationToken ) } ) ;
121+ PropertyInfo ? maxResponseContentBufferSizeProp = httpClientType . GetProperty ( "MaxResponseContentBufferSize" ) ;
118122 PropertyInfo ? responseContentProp = httpResponseMessageType . GetProperty ( "Content" ) ;
119123 PropertyInfo ? responseStatusCodeProp = httpResponseMessageType . GetProperty ( "StatusCode" ) ;
120124 PropertyInfo ? responseHeadersProp = httpResponseMessageType . GetProperty ( "Headers" ) ;
@@ -125,7 +129,7 @@ internal static partial class X509ResourceClient
125129 if ( socketsHttpHandlerCtor == null || pooledConnectionIdleTimeoutProp == null ||
126130 allowAutoRedirectProp == null || httpClientCtor == null ||
127131 requestUriProp == null || httpRequestMessageCtor == null ||
128- sendMethod == null || sendAsyncMethod == null ||
132+ sendMethod == null || sendAsyncMethod == null || maxResponseContentBufferSizeProp == null ||
129133 responseContentProp == null || responseStatusCodeProp == null ||
130134 responseHeadersProp == null || responseHeadersLocationProp == null ||
131135 readAsStreamMethod == null || taskOfHttpResponseMessageResultProp == null )
@@ -149,6 +153,7 @@ internal static partial class X509ResourceClient
149153 pooledConnectionIdleTimeoutProp . SetValue ( socketsHttpHandler , TimeSpan . FromSeconds ( PooledConnectionIdleTimeoutSeconds ) ) ;
150154 allowAutoRedirectProp . SetValue ( socketsHttpHandler , false ) ;
151155 object ? httpClient = httpClientCtor . Invoke ( new object ? [ ] { socketsHttpHandler } ) ;
156+ maxResponseContentBufferSizeProp . SetValue ( httpClient , AiaDownloadLimit ) ;
152157
153158 return async ( string uriString , CancellationToken cancellationToken , bool async ) =>
154159 {
@@ -306,5 +311,24 @@ private static bool IsAllowedScheme(string scheme)
306311 {
307312 return string . Equals( scheme , "http ", StringComparison . OrdinalIgnoreCase ) ;
308313 }
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+ }
309333 }
310334}
0 commit comments