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

Add Azure App Services middleware #188

Merged
merged 1 commit into from
Oct 12, 2023
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
6 changes: 6 additions & 0 deletions LogOtter.sln
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomerWorker", "sample\Cu
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LogOtter.Hub", "src\LogOtter.Hub\LogOtter.Hub.csproj", "{1DEBB304-17E4-4FAE-9772-3B3CC6DF8EEF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LogOtter.Azure.AppServices.RequestMiddleware", "src\LogOtter.Azure.AppServices.RequestMiddleware\LogOtter.Azure.AppServices.RequestMiddleware.csproj", "{A644FC0B-D646-49EB-91A1-0AC9CB719C74}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -130,6 +132,10 @@ Global
{1DEBB304-17E4-4FAE-9772-3B3CC6DF8EEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DEBB304-17E4-4FAE-9772-3B3CC6DF8EEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1DEBB304-17E4-4FAE-9772-3B3CC6DF8EEF}.Release|Any CPU.Build.0 = Release|Any CPU
{A644FC0B-D646-49EB-91A1-0AC9CB719C74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A644FC0B-D646-49EB-91A1-0AC9CB719C74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A644FC0B-D646-49EB-91A1-0AC9CB719C74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A644FC0B-D646-49EB-91A1-0AC9CB719C74}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5E67A3CB-9089-4AA1-802C-B8CF9DFEEF58} = {3013166D-3A9F-4979-B741-08D4288F5D28}
Expand Down
1 change: 1 addition & 0 deletions sample/CustomerApi/CustomerApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\LogOtter.Azure.AppServices.RequestMiddleware\LogOtter.Azure.AppServices.RequestMiddleware.csproj" />
<ProjectReference Include="..\..\src\LogOtter.CosmosDb.EventStore\LogOtter.CosmosDb.EventStore.csproj" />
<ProjectReference Include="..\..\src\LogOtter.HttpPatch\LogOtter.HttpPatch.csproj" />
<ProjectReference Include="..\..\src\LogOtter.JsonHal\LogOtter.JsonHal.csproj" />
Expand Down
3 changes: 3 additions & 0 deletions sample/CustomerApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using CustomerApi.HealthChecks;
using CustomerApi.NonEventSourcedData.CustomerInterests;
using CustomerApi.Services;
using LogOtter.Azure.AppServices.RequestMiddleware;
using LogOtter.CosmosDb;
using LogOtter.CosmosDb.EventStore;
using LogOtter.CosmosDb.EventStore.EventStreamApi;
Expand Down Expand Up @@ -84,7 +85,9 @@

var app = builder.Build();

app.UseRestoreRawRequestPathMiddleware();
app.UseCors();
app.UseAuthorization();

if (app.Environment.IsDevelopment())
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Builder;

namespace LogOtter.Azure.AppServices.RequestMiddleware;

public static class ConfigureExtensions
{
public static WebApplication UseRestoreRawRequestPathMiddleware(this WebApplication webApplication)
{
webApplication.UseMiddleware<RestoreRawRequestPathMiddleware>();
webApplication.UseRouting();

return webApplication;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>LogOtter.Azure.AppServices.RequestMiddleware</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions src/LogOtter.Azure.AppServices.RequestMiddleware/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
> ⚠️ Warning: LogOtter is still in beta and there are likely to be breaking changes prior to a v1 release. Use at your own peril!

# Azure AppServices RequestMiddleware

Adds middleware for converting the request back to the original request (Azure AppServices
decode path strings and there is currently no way to disable).

For more information see [dotnet/aspnetcore#40532](https://github.com/dotnet/aspnetcore/issues/40532)
and [Azure/azure-functions-host#9402](https://github.com/Azure/azure-functions-host/pull/9402#issuecomment-1747347531)

## Examples

Register the middleware

```c#
app.UseRestoreRawRequestPathMiddleware();
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.AspNetCore.Http;

namespace LogOtter.Azure.AppServices.RequestMiddleware;

public class RestoreRawRequestPathMiddleware
{
private const string UnencodedUrlHeaderName = "X-Waws-Unencoded-Url";

private readonly RequestDelegate _next;

public RestoreRawRequestPathMiddleware(RequestDelegate next)
{
_next = next;
}

public async Task Invoke(HttpContext context)
{
if (context.Request.Headers.TryGetValue(UnencodedUrlHeaderName, out var unencodedUrlValue) && unencodedUrlValue.Any())
{
context.Request.Path = new PathString(unencodedUrlValue.First());
}

await _next(context);
}
}
2 changes: 2 additions & 0 deletions src/LogOtter.Hub/LogOtter.Hub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\LogOtter.Azure.AppServices.RequestMiddleware\LogOtter.Azure.AppServices.RequestMiddleware.csproj" />
<ProjectReference Include="..\LogOtter.JsonHal\LogOtter.JsonHal.csproj" />
</ItemGroup>

Expand Down
2 changes: 2 additions & 0 deletions src/LogOtter.Hub/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using LogOtter.Azure.AppServices.RequestMiddleware;
using LogOtter.Hub.Configuration;
using LogOtter.Hub.Services;

Expand All @@ -22,6 +23,7 @@

app.ConfigureReverseProxy(serviceOptions);

app.UseRestoreRawRequestPathMiddleware();
app.UseCors();
app.UseFileServer();
app.UseRouting();
Expand Down