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
63 changes: 31 additions & 32 deletions dotnet/src/dotnetframework/GxClasses/Core/GXApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2425,62 +2425,59 @@ public byte SetHeader(string name, string value)
_httpHeaders = new NameValueCollection();
}
_httpHeaders[name] = value;
SetCustomHttpHeader(name, value);
return 0;
return SetCustomHttpHeader(name, value);
}

private void SetCustomHttpHeader(string name, string value)
private byte SetCustomHttpHeader(string name, string value)
{
try
{
#if !NETCORE

if (name.Equals(HeaderNames.CacheControl, StringComparison.OrdinalIgnoreCase))
{
if (System.Net.Http.Headers.CacheControlHeaderValue.TryParse(value, out System.Net.Http.Headers.CacheControlHeaderValue parsedValue))
{
HttpContext.Current.Response.CacheControl = parsedValue.ToString();
}
else
var Cache = _HttpContext.Response.Cache;
string[] values = value.Split(',');
foreach (string v in values)
{
var Cache = _HttpContext.Response.Cache;
string[] values = value.Split(',');
foreach (string v in values)
switch (v.Trim().ToUpper())
{
switch (v.Trim().ToUpper())
{
case "PUBLIC":
Cache.SetCacheability(HttpCacheability.Public);
break;
case "PRIVATE":
Cache.SetCacheability(HttpCacheability.Private);
break;
case "NO-CACHE":
Cache.SetCacheability(HttpCacheability.NoCache);
break;
case "NO-STORE":
Cache.AppendCacheExtension("no-store, must-revalidate");
break;
default:
GXLogging.Warn(log, String.Format("Could not set Cache Control Http Header Value '{0}' to HttpResponse", value));
break;
}
case "PUBLIC":
Cache.SetCacheability(HttpCacheability.Public);
break;
case "PRIVATE":
Cache.SetCacheability(HttpCacheability.Private);
break;
case "NO-CACHE":
Cache.SetCacheability(HttpCacheability.NoCache);
break;
case "NO-STORE":
Cache.AppendCacheExtension("no-store, must-revalidate");
break;
default:
GXLogging.Warn(log, String.Format("Could not set Cache Control Http Header Value '{0}' to HttpResponse", value));
break;
}
}
}
else if (name.Equals(HeaderNames.ContentType, StringComparison.OrdinalIgnoreCase))
{
_HttpContext.Response.ContentType = value;
}
else if (name.Equals(HeaderNames.Location, StringComparison.OrdinalIgnoreCase))
{
_HttpContext.Response.RedirectLocation = value;
}
else
{
if (!string.IsNullOrEmpty(_HttpContext.Response.Headers[name]))
try
{
_HttpContext.Response.Headers[name] = value;
}
else

}catch (PlatformNotSupportedException ex)
{
_HttpContext.Response.AppendHeader(name, value);
GXLogging.Warn(log, ex, "SetHeader ", name, value);
}
}
#else
Expand Down Expand Up @@ -2510,10 +2507,12 @@ private void SetCustomHttpHeader(string name, string value)
_HttpContext.Response.AddHeader(name, value);
}
#endif
return 0;
}
catch (Exception ex)
{
GXLogging.Error(log, ex, "Error adding header ", name, value);
return 1;
}
}

Expand Down
20 changes: 20 additions & 0 deletions dotnet/test/DotNetUnitTest/Domain/GxHttpClientTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
using System.IO;
using System.Net;
using GeneXus.Application;
using GeneXus.Http.Client;
using Xunit;
#if !NETCORE
using System.Web.SessionState;
using System.Web;
#endif

namespace xUnitTesting
{
Expand Down Expand Up @@ -39,6 +45,20 @@ public void HttpClientInvalidURLWithCustomPort()
Assert.NotEqual(((int)HttpStatusCode.InternalServerError), httpclient.StatusCode);
}
}
#if !NETCORE
[Fact]
public void NoStoreHeader()
{
var httpRequest = new HttpRequest("", "http://localhost/", "");
var httpResponce = new HttpResponse(new StringWriter());
var httpContext = new HttpContext(httpRequest, httpResponce);
HttpContext.Current = httpContext;

GxContext gxcontext = new GxContext();
gxcontext.HttpContext = HttpContext.Current;
byte result = gxcontext.SetHeader("CACHE", "no-store");
Assert.Equal(0, result);
}
#endif
}
}