Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 6270b91

Browse files
committed
Merge pull request #2784 from rajansingh10/mfeature
Enabled max redirection in HTTP xplat
2 parents f6e99e3 + 868da12 commit 6270b91

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

src/Common/src/Interop/Unix/libcurl/Interop.libcurl_types.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ internal static partial class CURLoption
3131
internal const int CURLOPT_UPLOAD = CurlOptionLongBase + 46;
3232
internal const int CURLOPT_FOLLOWLOCATION = CurlOptionLongBase + 52;
3333
internal const int CURLOPT_PROXYPORT = CurlOptionLongBase + 59;
34+
internal const int CURLOPT_MAXREDIRS = CurlOptionLongBase + 68;
3435
internal const int CURLOPT_PROXYTYPE = CurlOptionLongBase + 101;
3536

3637
internal const int CURLOPT_WRITEDATA = CurlOptionObjectPointBase + 1;

src/System.Net.Http/src/System/Net/Http/Unix/CurlHandler.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ internal partial class CurlHandler : HttpMessageHandler
4343

4444
private volatile bool _anyOperationStarted;
4545
private volatile bool _disposed;
46-
private bool _automaticRedirection = true;
4746
private IWebProxy _proxy = null;
4847
private ICredentials _serverCredentials = null;
4948
private ProxyUsePolicy _proxyPolicy = ProxyUsePolicy.UseDefaultProxy;
@@ -52,6 +51,8 @@ internal partial class CurlHandler : HttpMessageHandler
5251
private GCHandle _multiHandlePtr = new GCHandle();
5352
private CookieContainer _cookieContainer = null;
5453
private bool _useCookie = false;
54+
private bool _automaticRedirection = true;
55+
private int _maxAutomaticRedirections = 50;
5556

5657
#endregion
5758

@@ -104,6 +105,7 @@ internal bool UseProxy
104105
{
105106
return _proxyPolicy != ProxyUsePolicy.DoNotUseProxy;
106107
}
108+
107109
set
108110
{
109111
CheckDisposedOrStarted();
@@ -124,6 +126,7 @@ internal IWebProxy Proxy
124126
{
125127
return _proxy;
126128
}
129+
127130
set
128131
{
129132
CheckDisposedOrStarted();
@@ -137,6 +140,7 @@ internal ICredentials Credentials
137140
{
138141
return _serverCredentials;
139142
}
143+
140144
set
141145
{
142146
CheckDisposedOrStarted();
@@ -150,6 +154,7 @@ internal ClientCertificateOption ClientCertificateOptions
150154
{
151155
return ClientCertificateOption.Manual;
152156
}
157+
153158
set
154159
{
155160
if (ClientCertificateOption.Manual != value)
@@ -173,6 +178,7 @@ internal DecompressionMethods AutomaticDecompression
173178
{
174179
return _automaticDecompression;
175180
}
181+
176182
set
177183
{
178184
CheckDisposedOrStarted();
@@ -208,6 +214,28 @@ internal CookieContainer CookieContainer
208214
}
209215
}
210216

217+
internal int MaxAutomaticRedirections
218+
{
219+
get
220+
{
221+
return _maxAutomaticRedirections;
222+
}
223+
224+
set
225+
{
226+
if (value <= 0)
227+
{
228+
throw new ArgumentOutOfRangeException(
229+
"value",
230+
value,
231+
string.Format(SR.net_http_value_must_be_greater_than, 0));
232+
}
233+
234+
CheckDisposedOrStarted();
235+
_maxAutomaticRedirections = value;
236+
}
237+
}
238+
211239
#endregion
212240

213241
protected override void Dispose(bool disposing)
@@ -381,6 +409,9 @@ private SafeCurlHandle CreateRequestHandle(RequestCompletionSource state, GCHand
381409
if (_automaticRedirection)
382410
{
383411
SetCurlOption(requestHandle, CURLoption.CURLOPT_FOLLOWLOCATION, 1L);
412+
413+
// Set maximum automatic redirection option
414+
SetCurlOption(requestHandle, CURLoption.CURLOPT_MAXREDIRS, _maxAutomaticRedirections);
384415
}
385416
if (state.RequestMessage.Content != null)
386417
{

src/System.Net.Http/src/System/Net/Http/Unix/HttpClientHandler.Unix.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public ClientCertificateOption ClientCertificateOptions
5757
{
5858
return _curlHandler.ClientCertificateOptions;
5959
}
60+
6061
set
6162
{
6263
_curlHandler.ClientCertificateOptions = value;
@@ -105,6 +106,7 @@ public bool AllowAutoRedirect
105106
{
106107
return _curlHandler.AutomaticRedirection;
107108
}
109+
108110
set
109111
{
110112
_curlHandler.AutomaticRedirection = value;
@@ -113,8 +115,15 @@ public bool AllowAutoRedirect
113115

114116
public int MaxAutomaticRedirections
115117
{
116-
get { throw NotImplemented.ByDesignWithMessage("HTTP stack not implemented"); }
117-
set { throw NotImplemented.ByDesignWithMessage("HTTP stack not implemented"); }
118+
get
119+
{
120+
return _curlHandler.MaxAutomaticRedirections;
121+
}
122+
123+
set
124+
{
125+
_curlHandler.MaxAutomaticRedirections = value;
126+
}
118127
}
119128

120129
public long MaxRequestContentBufferSize

0 commit comments

Comments
 (0)