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
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,12 @@ internal static List<string> GetGxNamespaces(HttpContext context, string mainNam
try
{
string binPath = GxContext.StaticPhysicalPath();
if (context != null && !binPath.EndsWith("bin")){
GXLogging.Debug(log, $"binPath at GetGXNamespaces {binPath}");
if (context != null && !binPath.EndsWith("bin") && !GxContext.IsAzureContext){
binPath = Path.Combine(binPath, "bin");
}
string[] files = Directory.GetFiles(binPath, "*.Common.dll", SearchOption.TopDirectoryOnly);
if (files == null || files.Length == 0)
if ((files == null || files.Length == 0) && (!GxContext.IsAzureContext))
{
binPath = Path.Combine(binPath, "bin");
files = Directory.GetFiles(binPath, "*.Common.dll", SearchOption.TopDirectoryOnly);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.IO.Pipelines;
using System.Linq;
Expand All @@ -14,6 +16,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Primitives;

namespace GeneXus.Deploy.AzureFunctions.HttpHandler
{
Expand Down Expand Up @@ -45,7 +48,7 @@ public GXHttpAzureContextAccessor(HttpRequestData requestData, HttpResponseData
isSecure = GetSecureConnection(header.Key, defaultHttpContext.Request.Headers[header.Key]);

}
if (requestData.FunctionContext.BindingContext!=null)
if (requestData.FunctionContext.BindingContext != null)
{
IReadOnlyDictionary<string, object> keyValuePairs = requestData.FunctionContext.BindingContext.BindingData;
object queryparamsJson = requestData.FunctionContext.BindingContext.BindingData.GetValueOrDefault("Query");
Expand Down Expand Up @@ -83,7 +86,7 @@ public GXHttpAzureContextAccessor(HttpRequestData requestData, HttpResponseData
RedisHttpSession redisHttpSession = (RedisHttpSession)Session;
//Check if session is in cache
if (redisHttpSession.SessionKeyExists(sessionId))
{
{
bool success = redisHttpSession.RefreshSession(sessionId);
if (!success)
GXLogging.Debug(log, $"Azure Serverless: Session could not be refreshed :{sessionId}");
Expand All @@ -97,7 +100,7 @@ private bool GetSecureConnection(string headerKey, string headerValue)
{
if ((headerKey == "Front-End-Https") & (headerValue == "on"))
return true;

if ((headerKey == "X-Forwarded-Proto") & (headerValue == "https"))
return true;

Expand Down Expand Up @@ -126,7 +129,7 @@ private string CookieValue(string header, string name)
{
string[] words = header.Split(';');

foreach (var word in words)
foreach (string word in words)
{
string[] parts = word.Split('=');
if (parts[0].Trim() == name)
Expand Down Expand Up @@ -164,6 +167,104 @@ public override void Abort()
//throw new NotImplementedException();
}
}
internal class GxAzureResponseHeaders : IHeaderDictionary
{
HeaderDictionary m_headers;
HttpResponseData m_httpResponseData;
internal GxAzureResponseHeaders(HttpResponseData httpResponseData)
{
m_headers = new HeaderDictionary();
foreach (var header in httpResponseData.Headers)
{
string[] values = new Microsoft.Extensions.Primitives.StringValues(header.Value.Select(val => val).ToArray());
m_headers.Add(header.Key, values);
}
m_httpResponseData = httpResponseData;
}

public StringValues this[string key]
{
get
{
return m_headers[key];
}
set
{
m_httpResponseData.Headers.Add(key, value.AsEnumerable());
m_headers[key] = value;
}
}

public long? ContentLength { get { return m_headers.ContentLength; } set {; } }

public ICollection<string> Keys { get { return m_headers.Keys; } }
public ICollection<StringValues> Values { get { return m_headers.Values; } }

public int Count { get { return m_headers.Count; } }

public bool IsReadOnly { get { return m_headers.IsReadOnly; } }

public void Add(string key, StringValues value)
{
m_httpResponseData.Headers.Add(key, value.AsEnumerable());
m_headers.Add(key, value);
}

public void Add(KeyValuePair<string, StringValues> item)
{
m_httpResponseData.Headers.Add(item.Key, item.Value.AsEnumerable());
m_headers.Add(item.Key, item.Value);
}

public void Clear()
{
m_httpResponseData.Headers.Clear();
m_headers.Clear();
}

public bool Contains(KeyValuePair<string, StringValues> item)
{
return m_headers.Contains(item);
}

public bool ContainsKey(string key)
{
return m_headers.ContainsKey(key);
}

public void CopyTo(KeyValuePair<string, StringValues>[] array, int arrayIndex)
{
m_headers.CopyTo(array, arrayIndex);
}

public IEnumerator<KeyValuePair<string, StringValues>> GetEnumerator()
{
return m_headers.GetEnumerator();
}

public bool Remove(string key)
{
m_httpResponseData.Headers.Remove(key);
return m_headers.Remove(key);
}

public bool Remove(KeyValuePair<string, StringValues> item)
{
m_httpResponseData.Headers.Remove(item.Key);
return m_headers.Remove(item);
}

public bool TryGetValue(string key, [MaybeNullWhen(false)] out StringValues value)
{
return m_headers.TryGetValue(key, out value);
}

IEnumerator IEnumerable.GetEnumerator()
{
return m_headers.GetEnumerator();
}
}

public class GxHttpAzureResponse : HttpResponse
{
HttpResponseData httpResponseData;
Expand Down Expand Up @@ -212,13 +313,7 @@ public override IHeaderDictionary Headers
{
get
{
IHeaderDictionary headers = new HeaderDictionary();
foreach (var header in httpResponseData.Headers)
{
string[] values = new Microsoft.Extensions.Primitives.StringValues(header.Value.Select(val => val).ToArray());
headers.Add(header.Key, values);
}
return headers;
return new GxAzureResponseHeaders(httpResponseData);
}
}
public override Stream Body { get => httpResponseData.Body; set => httpResponseData.Body = value; }
Expand Down
1 change: 1 addition & 0 deletions dotnet/src/extensions/Azure/Handlers/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static async Task Main()
})
.Build();
GxContext.IsAzureContext = true;
GxContext.IsHttpContext = true;
await host.RunAsync();
}
private static string GetRoutePrefix(string ContentRootPath)
Expand Down