Skip to content

Commit

Permalink
send uri instead of port number
Browse files Browse the repository at this point in the history
  • Loading branch information
satvu committed Apr 11, 2023
1 parent 621264b commit e7ef6f4
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.Functions.Worker.Core.Http;
using Microsoft.Azure.Functions.Worker.Extensions.Http.AspNet;
using Microsoft.Extensions.Primitives;

namespace Microsoft.Azure.Functions.Worker.Core.Pipeline
Expand All @@ -23,7 +24,7 @@ public AspNetMiddleware(RequestDelegate next, IHttpCoordinator httpCoordinator)

public async Task Invoke(HttpContext context)
{
context.Request.Headers.TryGetValue("invocation-id", out StringValues invocationId);
context.Request.Headers.TryGetValue(Constants.CorrelationHeader, out StringValues invocationId);

if (invocationId == 0 || invocationId.Count == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace Microsoft.Azure.Functions.Worker.Extensions.Http.AspNet
internal static class Constants
{
// Rpc Constants
internal const string HttpProxyingPortCapability = "HttpProxyingPort";
internal const string HttpUriCapability = "HttpUri";

// Header constants
internal const string CorrelationHeader = "x-invocation-id";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public DefaultHttpCoordinator()
_httpContextReferenceList = new ConcurrentDictionary<string, HttpContextReference>();
}


public Task SetContextAsync(string invocationId, HttpContext context)
{
var httpContextRef = _httpContextReferenceList.AddOrUpdate(invocationId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Azure.Functions.Worker.Core.Pipeline;
using Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

Expand All @@ -24,7 +26,7 @@ public static IHostBuilder ConfigureAspNetCoreIntegration(this IHostBuilder buil
{
builder.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseUrls("http://localhost:5555");
webBuilder.UseUrls(HttpUriProvider.GetHttpUri().ToString());
webBuilder.Configure(b =>
{
b.UseAspNetHttpForwarderMiddleware();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using Microsoft.Azure.Functions.Worker.Core.Http;

namespace Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore
{
internal static class HttpUriProvider
{
private static Uri? _httpUri;

public static Lazy<int> HttpPort = new Lazy<int>(() => Utilities.GetUnusedTcpPort());

public static Uri GetHttpUri()
{
if (_httpUri is not null)
{
return _httpUri;
}

// TODO: replace local host string
var uriString = "http://localhost:" + HttpPort.Value.ToString();

return new Uri(uriString);
}

public static string GetHttpUriAsString()
{
return GetHttpUri().ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Azure.Functions.Worker.Converters;
using Microsoft.Azure.Functions.Worker.Core.Http;
using Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore;
using Microsoft.Azure.Functions.Worker.Pipeline;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -39,7 +40,7 @@ public static IFunctionsWorkerApplicationBuilder UseAspNetCoreIntegration(this I
builder.Services.Configure<WorkerOptions>((workerOption) =>
{
workerOption.InputConverters.RegisterAt<HttpContextConverter>(0);
workerOption.Capabilities.Add(Constants.HttpProxyingPortCapability, "5555"); // testing host side, remove this const later
workerOption.Capabilities.Add(Constants.HttpUriCapability, HttpUriProvider.GetHttpUri().ToString()); // testing host side, remove this const later
});

return builder;
Expand Down

0 comments on commit e7ef6f4

Please sign in to comment.