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

ASP.NET Core integration with ConfigureFunctionsWebApplication overwrite host url in the bindings of request (HttpRequestData) #2071

Closed
Schulungkubanetis opened this issue Nov 16, 2023 · 7 comments · Fixed by #2149
Assignees

Comments

@Schulungkubanetis
Copy link

Schulungkubanetis commented Nov 16, 2023

There is a problem to use the request url of HttpRequestData when using the ConfigureFunctionsWebApplication extension method.
Therefore the openapi integration https://github.com/Azure/azure-functions-openapi-extension is not working because the asp integration overwrite the url of HttpRequestData.
Is it possible to change the integration to a proper mapping so the primary values come from the binding and not form the default values of the asp integration itself?

image

@y2k4life
Copy link

y2k4life commented Nov 18, 2023

My solution was to configure OpenAPI using the port information found in launchSettings.json.

In your case http://localhost:7194/api/

Overriding Base URLs
Advanced Configuration in General

.
.
.
    .ConfigureServices(services =>
    {
        services.AddSingleton<IOpenApiConfigurationOptions>(_ =>
        {
            var options = new OpenApiConfigurationOptions()
            {
                Servers = new List<OpenApiServer>()
                    {
                        new OpenApiServer() { Url = "http://localhost:7141/api/" }
                    }
            };

            return options;
        });
    
    })
.
.
.

@Schulungkubanetis
Copy link
Author

launchSettings

Good to know that there is a workarround. But I hope this is properly solved in the future.

@fabiocav
Copy link
Member

@Schulungkubanetis should this me move to/tracked in the OpenAPI extension repo?

Thanks!

@Schulungkubanetis
Copy link
Author

Schulungkubanetis commented Nov 22, 2023

@Schulungkubanetis should this me move to/tracked in the OpenAPI extension repo?

Thanks!

My undestanding ist that the url from the host which comes normaly with https://github.com/Azure/azure-functions-dotnet-worker/blob/main/src/DotNetWorker.Grpc/Http/GrpcHttpRequestData.cs is overwrite with https://github.com/Azure/azure-functions-dotnet-worker/blob/main/extensions/Worker.Extensions.Http.AspNetCore/src/HttpDataModel/AspNetCoreHttpRequestData.cs which get the url in AspNetCoreHttpRequestDataFeature from the generated httpcontext which is not equal.
If the difference between HttpRequestData:GrpcHttpRequestData.Url and HttpRequestData:AspNetCoreHttpRequestData.Url is intentionally and the AspNetCoreHttpRequestData.Url should be different from the host url than yes it should be moved?
I'm not sure how it can be used because AspNetCoreHttpRequestData.Url is every time localhost not only local but also deployed.

@fabiocav
Copy link
Member

@Schulungkubanetis thank you for the additional details. This is a little clearer now. Will take a look at this in the coming sprint.

@fabiocav fabiocav self-assigned this Nov 23, 2023
@fabiocav fabiocav assigned satvu and unassigned fabiocav Nov 27, 2023
@gorillapower
Copy link

I am seeing a similar issue where HttpRequest.GetDisplayUrl() or HttpRequestData.Url.AbsoluteUri returns the internal Grpc localhost url. So even when hosted in azure, when I inspect the incoming request URL, it resembles the following
image
*GetHttpRequestDataAsync().Url.AbsoluteUri

  1. Is this is expected? Its a depature from in-proc and I can see why it might be happening, but not sure if its expected behaviour. If its, I believe a note in the migration documentation highlighting this change would be helpful to users.

  2. Is there a way to get the original request url? In my case my work around might work, but if the request uses a custom hostname, it wont work.

Current workaround is to reference the Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME")

@fabiocav fabiocav changed the title Asp integration with ConfigureFunctionsWebApplication overwrite host url in the bindings of request (HttpRequestData) ASP.NET Core integration with ConfigureFunctionsWebApplication overwrite host url in the bindings of request (HttpRequestData) Dec 6, 2023
@fabiocav
Copy link
Member

Thank you all. We have clarity on the issue here and will have an update to address this behavior as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants