Skip to content

Commit 4e20cb3

Browse files
Add trace for HttpClient.
Ignore cookies in container that are invalid for the current url.
1 parent 1372598 commit 4e20cb3

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

dotnet/src/dotnetframework/GxClasses/Domain/GxHttpClient.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ private static HttpClient GetHttpClientInstance(Uri URI, int timeout, ArrayList
161161
string key = HttpClientInstanceIdentifier(proxyHost, proxyPort, fileCertificateCollection, timeout);
162162
if (_httpClientInstances.TryGetValue(key, out value))
163163
{
164+
GXLogging.Debug(log, $"Getting httpClient cached instance");
164165
return value;
165166
}
166167
else
@@ -169,6 +170,7 @@ private static HttpClient GetHttpClientInstance(Uri URI, int timeout, ArrayList
169170
{
170171
if (_httpClientInstances.TryGetValue(key, out value))
171172
{
173+
GXLogging.Debug(log, $"Getting httpClient cached instance");
172174
return value;
173175
}
174176
value = new HttpClient(GetHandler(URI, authCollection, authProxyCollection, certificateCollection, proxyHost, proxyPort));
@@ -212,10 +214,11 @@ private static SocketsHttpHandler GetHandler(Uri URI, ArrayList authCollection,
212214
PooledConnectionLifetime = TimeSpan.FromMinutes(POOLED_CONNECTION_LIFETIME_MINUTES),
213215
};
214216
int maxConnections = Preferences.GetHttpClientMaxConnectionPerRoute();
215-
if (maxConnections != 0)
217+
if (maxConnections != Preferences.DEFAULT_HTTPCLIENT_MAX_PER_ROUTE)
216218
{
217219
handler.MaxConnectionsPerServer = maxConnections;
218220
}
221+
GXLogging.Debug(log, $"Creating SocketsHttpHandler MaxConnectionsPerServer:{handler.MaxConnectionsPerServer}");
219222
handler.Credentials = getCredentialCache(URI, authCollection);
220223

221224
if (ServicePointManager.ServerCertificateValidationCallback != null)

dotnet/src/dotnetframework/GxClasses/Helpers/HttpHelper.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public class WrappedJsonError
7676
#if NETCORE
7777
internal static class CookiesHelper
7878
{
79+
static readonly IGXLogger log = GXLoggerFactory.GetLogger(typeof(CookiesHelper).FullName);
80+
7981
internal static void PopulateCookies(this HttpRequestMessage request, CookieContainer cookieContainer)
8082
{
8183
if (cookieContainer != null)
@@ -94,12 +96,19 @@ private static string ToHeaderFormat(this IEnumerable<Cookie> cookies)
9496
}
9597
internal static void ExtractCookies(this HttpResponseMessage response, CookieContainer cookieContainer)
9698
{
97-
if (response.Headers.TryGetValues("Set-Cookie", out var cookieEntries))
99+
if (response.Headers.TryGetValues("Set-Cookie", out var cookieValues))
98100
{
99101
Uri uri = response.RequestMessage.RequestUri;
100-
foreach (string cookieEntry in cookieEntries)
102+
foreach (string cookieValue in cookieValues)
101103
{
102-
cookieContainer.SetCookies(uri, cookieEntry);
104+
try
105+
{
106+
cookieContainer.SetCookies(uri, cookieValue);
107+
}
108+
catch (CookieException ex)
109+
{
110+
GXLogging.Warn(log, $"Ignored cookie for container: {cookieValue} url:{uri}", ex);
111+
}
103112
}
104113

105114
}

0 commit comments

Comments
 (0)