Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: v3 .NET #144

Merged
merged 16 commits into from
Jun 8, 2023
Prev Previous commit
Next Next commit
Fix dotnet according to V3 tests
  • Loading branch information
Meldiron committed Feb 9, 2023
commit 62ac21150c29f8cec69013dbc13ccea9e3077f96
19 changes: 11 additions & 8 deletions runtimes/dotnet-6.0/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
static async Task<IResult> Execute(HttpRequest Request)
{
string Secret = Request.Headers.TryGetValue("x-open-runtimes-secret", out var SecretValue) ? (string) SecretValue : "";
if(Secret != (Environment.GetEnvironmentVariable("OPEN_RUNTIMES_SECRET") ?? ""))
if(Secret == "" || Secret != (Environment.GetEnvironmentVariable("OPEN_RUNTIMES_SECRET") ?? ""))
{
return new CustomResponse("Unauthorized. Provide correct \"x-open-runtimes-secret\" header.", 500);
}
Expand Down Expand Up @@ -56,8 +56,11 @@ static async Task<IResult> Execute(HttpRequest Request)

String HostHeader = Request.Headers.TryGetValue("host", out var HostHeaderValue) ? (string) HostHeaderValue : "";
Meldiron marked this conversation as resolved.
Show resolved Hide resolved

String Scheme = Request.Headers.TryGetValue("x-forwarded-proto", out var ProtoHeaderValue) ? (string) ProtoHeaderValue : "http";
String DefaultPort = Scheme == "https" ? "443" : "80";

String Host = "";
int Port = 80;
int Port = Int32.Parse(DefaultPort);

if(HostHeader.Contains(":"))
{
Expand All @@ -66,10 +69,9 @@ static async Task<IResult> Execute(HttpRequest Request)
} else
{
Host = HostHeader;
Port = 80;
Port = Int32.Parse(DefaultPort);
}

String Scheme = Request.Headers.TryGetValue("x-forwarded-proto", out var ProtoHeaderValue) ? (string) ProtoHeaderValue : "http";
String Path = Request.Path;

String QueryString = Request.QueryString.Value ?? "";
Expand All @@ -81,16 +83,17 @@ static async Task<IResult> Execute(HttpRequest Request)

foreach (String param in QueryString.Split("&"))
{
String[] pair = param.Split("=");
String[] pair = param.Split("=", 2);

if(pair.Length == 2 && !String.IsNullOrEmpty(pair[0])) {
Query.Add(pair[0], pair[1]);
if(pair.Length >= 1 && !String.IsNullOrEmpty(pair[0])) {
String Value = pair.Length == 2 ? pair[1] : "";
Query.Add(pair[0], Value);
}
}

String Url = Scheme + ":https://" + Host;

if(Port != 80)
if(Port != Int32.Parse(DefaultPort))
{
Url += ":" + Port.ToString();
}
Expand Down