44using System . IO . Compression ;
55using System . Reflection ;
66using System . Security . Cryptography ;
7+ using System . Text . RegularExpressions ;
78using Microsoft . AspNetCore . StaticFiles ;
89using Microsoft . Extensions . Primitives ;
910using Microsoft . Net . Http . Headers ;
@@ -13,8 +14,11 @@ namespace Microsoft.Agents.AI.DevUI;
1314/// <summary>
1415/// Handler that serves embedded DevUI resource files from the 'resources' directory.
1516/// </summary>
16- internal sealed class DevUIMiddleware
17+ internal sealed partial class DevUIMiddleware
1718{
19+ [ GeneratedRegex ( @"[\r\n]+" ) ]
20+ private static partial Regex NewlineRegex ( ) ;
21+
1822 private const string GZipEncodingValue = "gzip" ;
1923 private static readonly StringValues s_gzipEncodingHeader = new ( GZipEncodingValue ) ;
2024 private static readonly Assembly s_assembly = typeof ( DevUIMiddleware ) . Assembly ;
@@ -70,15 +74,16 @@ public async Task HandleRequestAsync(HttpContext context)
7074 // This ensures relative URLs in the HTML work correctly
7175 if ( string . Equals ( path , this . _basePath , StringComparison . OrdinalIgnoreCase ) && ! path . EndsWith ( '/' ) )
7276 {
73- var redirectUrl = $ " { path } /";
77+ var redirectUrl = this . _basePath + " /";
7478 if ( context . Request . QueryString . HasValue )
7579 {
7680 redirectUrl += context . Request . QueryString . Value ;
7781 }
7882
7983 context . Response . StatusCode = StatusCodes . Status301MovedPermanently ;
8084 context . Response . Headers . Location = redirectUrl ;
81- this . _logger . LogDebug ( "Redirecting {OriginalPath} to {RedirectUrl}" , path , redirectUrl ) ;
85+
86+ this . _logger . LogDebug ( "Redirecting {OriginalPath} to {RedirectUrl}" , NewlineRegex ( ) . Replace ( path , "" ) , NewlineRegex ( ) . Replace ( redirectUrl , "" ) ) ;
8287 return ;
8388 }
8489
0 commit comments