Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion dotnet/src/dotnetframework/GxClasses/Domain/GxHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,12 @@ void setHeaders(HttpRequestMessage request, CookieContainer cookies)
{
if (cookie.Contains("="))
{
cookies.Add(new Uri(request.RequestUri.Host), new Cookie(cookie.Split('=')[0], cookie.Split('=')[1]) { Domain = request.RequestUri.Host });
UriBuilder uriBuilder = new UriBuilder(request.RequestUri.Scheme, request.RequestUri.Host);
Cookie pCookie = ParseCookie(cookie, request.RequestUri.Host);
if (pCookie != null)
{
cookies.Add(uriBuilder.Uri, pCookie);
}
}
}
break;
Expand All @@ -608,6 +613,16 @@ void setHeaders(HttpRequestMessage request, CookieContainer cookies)
}
InferContentType(contentType, request);
}
Cookie ParseCookie(string cookie, string domain)
{
string[] values = cookie.TrimEnd(';').Split('=');
if (values.Length >= 2) {
string cookieName = values[0].Trim();
string cookieValue = values[1];
return new Cookie(cookieName, cookieValue) { Domain = domain };
}
return null;
}
void AddHeader(HttpRequestHeaders headers, string headerName, string headerValue)
{
headers.TryAddWithoutValidation(headerName, headerValue);
Expand Down
27 changes: 26 additions & 1 deletion dotnet/test/DotNetUnitTest/Domain/GxHttpClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public void AddHeaderWithSpecialCharactersDoesNotThrowException()
httpclient.Execute("GET", string.Empty);
Assert.NotEqual(((int)HttpStatusCode.InternalServerError), httpclient.StatusCode);
}

}

[Fact]
Expand All @@ -45,6 +44,32 @@ public void HttpClientInvalidURLWithCustomPort()
Assert.NotEqual(((int)HttpStatusCode.InternalServerError), httpclient.StatusCode);
}
}

[Fact]
public void HttpClientCookieHeader()
{
string headerValue = "CognitoIdentityServiceProvider.3tgmin25m9bkg6vgi7vpavu7a9.M00000936.refreshToken=eyJjdHkiOiJKV1QiLCJlbmMiSkRCAmMpYqndvORnWLTfHw; CognitoIdentityServiceProvider.3tgmin25m9bkg6vgi7vpavu7a9.LastAuthUser=M00000936";
string headerName = "Cookie";
using (GxHttpClient httpclient = new GxHttpClient())
{
httpclient.AddHeader(headerName, headerValue);
httpclient.Host = "localhost";
httpclient.Port = 80;
httpclient.BaseURL = @"NotFound/NotFound.php";
httpclient.HttpClientExecute("GET", string.Empty);
Assert.NotEqual(((int)HttpStatusCode.InternalServerError), httpclient.StatusCode);
}
using (GxHttpClient oldHttpclient = new GxHttpClient())
{
oldHttpclient.AddHeader(headerName, headerValue);
oldHttpclient.Host = "localhost";
oldHttpclient.Port = 80;
oldHttpclient.BaseURL = @"NotFound/NotFound.php";
oldHttpclient.Execute("GET", string.Empty);
Assert.NotEqual(((int)HttpStatusCode.InternalServerError), oldHttpclient.StatusCode);
}

}
#if !NETCORE
[Fact]
public void NoStoreHeader()
Expand Down