Skip to content

Commit

Permalink
Issue 108639 web request tab (#1036)
Browse files Browse the repository at this point in the history
* issue:108639 WEB tabId at gxhttprequest

* 108639 rev 2

* tomaster

* avoiding exceptions for non-popup requests

* Add defensive programming to prevent errors when httprequest.TabId is used on command line programs.

---------

Co-authored-by: Claudia Murialdo <[email protected]>
  • Loading branch information
dmendez and claudiamurialdo authored Dec 2, 2024
1 parent 0bbd3a6 commit 6b8fd10
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 42 deletions.
10 changes: 8 additions & 2 deletions dotnet/src/dotnetframework/GxClasses/Core/GXApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1684,9 +1684,9 @@ public string RemoveInternalParms(string query)
query = RemoveInternalSuffixes(query);
return query;
}
internal static string RemoveInternalSuffixes(string query)
internal static string RemoveInternalSuffix(string query, string param)
{
int idx = query.IndexOf(GXNavigationHelper.POPUP_LEVEL);
int idx = query.IndexOf(param);
if (idx == 1)
return "";
if (idx > 1)
Expand All @@ -1699,6 +1699,12 @@ internal static string RemoveInternalSuffixes(string query)
}
return query;
}

internal static string RemoveInternalSuffixes(string query)
{
query = RemoveInternalSuffix(query, GXNavigationHelper.POPUP_LEVEL);
return RemoveInternalSuffix(query, GXNavigationHelper.TAB_ID);
}
private string RemoveEventPrefix(string query)
{
if (IsGxAjaxRequest() || isAjaxEventMode())
Expand Down
54 changes: 42 additions & 12 deletions dotnet/src/dotnetframework/GxClasses/Core/Web/GxHttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ public class GxHttpRequest
{
HttpRequest _httpReq;
IGxContext _context;
string _referrer = "";
string _referrer = string.Empty;
string _tabId = string.Empty;

public GxHttpRequest(IGxContext context)
{
Expand All @@ -213,7 +214,7 @@ public string Method
get
{
if (_httpReq == null)
return "";
return string.Empty;
return _httpReq.GetMethod();
}
}
Expand All @@ -223,14 +224,14 @@ public short ErrCode
}
public string ErrDescription
{
get {return "";}
get {return string.Empty; }
}
public string BaseURL
{
get
{
if (_httpReq == null)
return "";
return string.Empty;
#if NETCORE
string baseURL = _httpReq.GetDisplayUrl();
#else
Expand All @@ -246,7 +247,7 @@ public string QueryString
get
{
if (_httpReq == null)
return "";
return string.Empty;
string urlQuery;
#if NETCORE
urlQuery = _httpReq.QueryString.HasValue ? _httpReq.QueryString.Value : string.Empty;
Expand All @@ -258,15 +259,15 @@ public string QueryString
string url = (_context != null && _context.isAjaxRequest()) ?
((GxContext)_context).RemoveInternalParms(urlQuery) :
urlQuery.Substring(1, urlQuery.Length - 1);
return url.Replace("?","");
return url.Replace("?", string.Empty);
}
}
public string ServerHost
{
get
{
if (_httpReq == null)
return "";
return string.Empty;
return _context.GetServerName();
}
}
Expand All @@ -293,7 +294,7 @@ public string ScriptPath
get
{
if (_httpReq == null)
return "";
return string.Empty;
return _httpReq.GetApplicationPath()+"/";
}
}
Expand All @@ -302,7 +303,7 @@ public string ScriptName
get
{
if (_httpReq == null)
return "";
return string.Empty;
string virtualPath = _httpReq.GetFilePath();
return virtualPath.Remove(0, virtualPath.LastIndexOf('/')+1) ;
}
Expand All @@ -322,10 +323,39 @@ public string Referrer
}
catch
{
return "";
return string.Empty;
}
}
}

public string TabId
{
get
{
if (_httpReq == null)
return string.Empty;

string sUrl = string.Empty;

#if NETCORE
sUrl = _httpReq.GetDisplayUrl();
#else
sUrl = _httpReq.Url.ToString();
#endif

if (string.IsNullOrEmpty(_tabId))
{
_tabId = GXNavigationHelper.getUrlComponent(sUrl, GXNavigationHelper.TAB_ID);
}
if (string.IsNullOrEmpty(_tabId))
{
_tabId = GetHeader(GXNavigationHelper.TAB_ID_HEADER);

}
return _tabId;
}
}

public string RemoteAddress
{
get
Expand Down Expand Up @@ -360,10 +390,10 @@ public string[] GetVariables()
public string GetHeader( string name)
{
if (_httpReq == null)
return "";
return string.Empty;
string hdr = _httpReq.Headers[name];
if (hdr == null)
return "";
return string.Empty;
return hdr;
}
public string GetValue( string name)
Expand Down
73 changes: 45 additions & 28 deletions dotnet/src/dotnetframework/GxClasses/Helpers/GXNavigationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace GeneXus.Application
public class GXNavigationHelper
{
public static string POPUP_LEVEL = "gxPopupLevel";
public static string TAB_ID = "gxTabId";
public static string TAB_ID_HEADER = "X-Gx-Tabid";
public static string CALLED_AS_POPUP = "gxCalledAsPopup";

[System.Diagnostics.CodeAnalysis.SuppressMessage("GxFxCopRules", "CR1000:EnforceThreadSafeType")]
Expand Down Expand Up @@ -122,43 +124,58 @@ public int Count()
return referers.Count;
}

public int GetUrlPopupLevel(string url)
internal static string getUrlComponent(string url, string key) {
Uri uri = null;
string result = "";
try
{
Uri uri = null;
try
{
uri = new Uri(url);
}
catch { }
if (uri != null)
{
url = uri.GetComponents(UriComponents.Query, UriFormat.Unescaped);
}
int popupLevel = -1;
if (url != null)
uri = new Uri(url);
}
catch { }
if (uri != null)
{
url = uri.GetComponents(UriComponents.Query, UriFormat.Unescaped);
}
if (url != null)
{
int pIdx = url.IndexOf(key);
if (pIdx != -1)
{
int pIdx = url.IndexOf(POPUP_LEVEL);
if (pIdx != -1)
int eqIdx = url.IndexOf("=", pIdx);
if (eqIdx != -1)
{
int eqIdx = url.IndexOf("=", pIdx);
if (eqIdx != -1)
int cIdx = url.IndexOf(";", eqIdx);
if (cIdx > eqIdx)
{
int cIdx = url.IndexOf(";", eqIdx);
if (cIdx > eqIdx)
try
{
result = url.Substring(eqIdx + 1, cIdx - eqIdx - 1);
}
catch
{
try
{
string strLvl = url.Substring(eqIdx + 1, cIdx - eqIdx - 1);
popupLevel = int.Parse(strLvl);
}
catch
{
popupLevel = -1;
}
}
}
}
}
}
return result;
}

public int GetUrlPopupLevel(string url)
{
int popupLevel = -1;
string sPopUpLvl = getUrlComponent(url, POPUP_LEVEL);
try
{
if (!String.IsNullOrEmpty(sPopUpLvl))
{
popupLevel = int.Parse(sPopUpLvl);
}
}
catch
{
popupLevel = -1;
}
return popupLevel;
}
}
Expand Down

0 comments on commit 6b8fd10

Please sign in to comment.