diff --git a/AspNetCore.sln b/AspNetCore.sln
index 03ad965f2bf1..19a61c8895b4 100644
--- a/AspNetCore.sln
+++ b/AspNetCore.sln
@@ -1232,12 +1232,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.FilePr
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{0B200A66-B809-4ED3-A790-CB1C2E80975E}"
EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dotnet-watch", "dotnet-watch", "{B6118E15-C37A-4B05-B4DF-97FE99790417}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-watch", "src\Tools\dotnet-watch\src\dotnet-watch.csproj", "{D0ADA8EC-F431-43C8-A86E-FE6A1E906512}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-watch.Tests", "src\Tools\dotnet-watch\test\dotnet-watch.Tests.csproj", "{95920BAA-46E6-44E6-A1AF-A23804F079D2}"
-EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dotnet-dev-certs", "dotnet-dev-certs", "{A4EECF29-6E66-4E7F-B781-A169B0C2AB29}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-dev-certs", "src\Tools\dotnet-dev-certs\src\dotnet-dev-certs.csproj", "{52433D20-35EA-48CC-BB4A-4DFE3023670B}"
@@ -1438,10 +1432,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RequestHandlerLib", "src\Se
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.ANCMSymbols", "src\Servers\IIS\AspNetCoreModuleV2\Symbols\Microsoft.AspNetCore.ANCMSymbols.csproj", "{7E268085-1046-4362-80CB-2977FF826DCA}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Watch.BrowserRefresh", "src\Tools\dotnet-watch\BrowserRefresh\src\Microsoft.AspNetCore.Watch.BrowserRefresh.csproj", "{A5CE25E9-89E1-4F2C-9B89-0C161707E700}"
-EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Watch.BrowserRefresh.Tests", "src\Tools\dotnet-watch\BrowserRefresh\test\Microsoft.AspNetCore.Watch.BrowserRefresh.Tests.csproj", "{E6A23627-8D63-4DF1-A4F2-8881172C1FE6}"
-EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "testassets", "testassets", "{7D2B0799-A634-42AC-AE77-5D167BA51389}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HostedInAspNet.Client", "src\Components\WebAssembly\testassets\HostedInAspNet.Client\HostedInAspNet.Client.csproj", "{9788C76F-658B-4441-88F8-22C6B86FAD27}"
@@ -5992,30 +5982,6 @@ Global
{65EE0531-4533-407F-A9CA-2EBCDC444397}.Release|x64.Build.0 = Release|Any CPU
{65EE0531-4533-407F-A9CA-2EBCDC444397}.Release|x86.ActiveCfg = Release|Any CPU
{65EE0531-4533-407F-A9CA-2EBCDC444397}.Release|x86.Build.0 = Release|Any CPU
- {D0ADA8EC-F431-43C8-A86E-FE6A1E906512}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {D0ADA8EC-F431-43C8-A86E-FE6A1E906512}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {D0ADA8EC-F431-43C8-A86E-FE6A1E906512}.Debug|x64.ActiveCfg = Debug|Any CPU
- {D0ADA8EC-F431-43C8-A86E-FE6A1E906512}.Debug|x64.Build.0 = Debug|Any CPU
- {D0ADA8EC-F431-43C8-A86E-FE6A1E906512}.Debug|x86.ActiveCfg = Debug|Any CPU
- {D0ADA8EC-F431-43C8-A86E-FE6A1E906512}.Debug|x86.Build.0 = Debug|Any CPU
- {D0ADA8EC-F431-43C8-A86E-FE6A1E906512}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {D0ADA8EC-F431-43C8-A86E-FE6A1E906512}.Release|Any CPU.Build.0 = Release|Any CPU
- {D0ADA8EC-F431-43C8-A86E-FE6A1E906512}.Release|x64.ActiveCfg = Release|Any CPU
- {D0ADA8EC-F431-43C8-A86E-FE6A1E906512}.Release|x64.Build.0 = Release|Any CPU
- {D0ADA8EC-F431-43C8-A86E-FE6A1E906512}.Release|x86.ActiveCfg = Release|Any CPU
- {D0ADA8EC-F431-43C8-A86E-FE6A1E906512}.Release|x86.Build.0 = Release|Any CPU
- {95920BAA-46E6-44E6-A1AF-A23804F079D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {95920BAA-46E6-44E6-A1AF-A23804F079D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {95920BAA-46E6-44E6-A1AF-A23804F079D2}.Debug|x64.ActiveCfg = Debug|Any CPU
- {95920BAA-46E6-44E6-A1AF-A23804F079D2}.Debug|x64.Build.0 = Debug|Any CPU
- {95920BAA-46E6-44E6-A1AF-A23804F079D2}.Debug|x86.ActiveCfg = Debug|Any CPU
- {95920BAA-46E6-44E6-A1AF-A23804F079D2}.Debug|x86.Build.0 = Debug|Any CPU
- {95920BAA-46E6-44E6-A1AF-A23804F079D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {95920BAA-46E6-44E6-A1AF-A23804F079D2}.Release|Any CPU.Build.0 = Release|Any CPU
- {95920BAA-46E6-44E6-A1AF-A23804F079D2}.Release|x64.ActiveCfg = Release|Any CPU
- {95920BAA-46E6-44E6-A1AF-A23804F079D2}.Release|x64.Build.0 = Release|Any CPU
- {95920BAA-46E6-44E6-A1AF-A23804F079D2}.Release|x86.ActiveCfg = Release|Any CPU
- {95920BAA-46E6-44E6-A1AF-A23804F079D2}.Release|x86.Build.0 = Release|Any CPU
{52433D20-35EA-48CC-BB4A-4DFE3023670B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{52433D20-35EA-48CC-BB4A-4DFE3023670B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{52433D20-35EA-48CC-BB4A-4DFE3023670B}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -6893,30 +6859,6 @@ Global
{7E268085-1046-4362-80CB-2977FF826DCA}.Release|x64.Build.0 = Release|Any CPU
{7E268085-1046-4362-80CB-2977FF826DCA}.Release|x86.ActiveCfg = Release|Any CPU
{7E268085-1046-4362-80CB-2977FF826DCA}.Release|x86.Build.0 = Release|Any CPU
- {A5CE25E9-89E1-4F2C-9B89-0C161707E700}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {A5CE25E9-89E1-4F2C-9B89-0C161707E700}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {A5CE25E9-89E1-4F2C-9B89-0C161707E700}.Debug|x64.ActiveCfg = Debug|Any CPU
- {A5CE25E9-89E1-4F2C-9B89-0C161707E700}.Debug|x64.Build.0 = Debug|Any CPU
- {A5CE25E9-89E1-4F2C-9B89-0C161707E700}.Debug|x86.ActiveCfg = Debug|Any CPU
- {A5CE25E9-89E1-4F2C-9B89-0C161707E700}.Debug|x86.Build.0 = Debug|Any CPU
- {A5CE25E9-89E1-4F2C-9B89-0C161707E700}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {A5CE25E9-89E1-4F2C-9B89-0C161707E700}.Release|Any CPU.Build.0 = Release|Any CPU
- {A5CE25E9-89E1-4F2C-9B89-0C161707E700}.Release|x64.ActiveCfg = Release|Any CPU
- {A5CE25E9-89E1-4F2C-9B89-0C161707E700}.Release|x64.Build.0 = Release|Any CPU
- {A5CE25E9-89E1-4F2C-9B89-0C161707E700}.Release|x86.ActiveCfg = Release|Any CPU
- {A5CE25E9-89E1-4F2C-9B89-0C161707E700}.Release|x86.Build.0 = Release|Any CPU
- {E6A23627-8D63-4DF1-A4F2-8881172C1FE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {E6A23627-8D63-4DF1-A4F2-8881172C1FE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {E6A23627-8D63-4DF1-A4F2-8881172C1FE6}.Debug|x64.ActiveCfg = Debug|Any CPU
- {E6A23627-8D63-4DF1-A4F2-8881172C1FE6}.Debug|x64.Build.0 = Debug|Any CPU
- {E6A23627-8D63-4DF1-A4F2-8881172C1FE6}.Debug|x86.ActiveCfg = Debug|Any CPU
- {E6A23627-8D63-4DF1-A4F2-8881172C1FE6}.Debug|x86.Build.0 = Debug|Any CPU
- {E6A23627-8D63-4DF1-A4F2-8881172C1FE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {E6A23627-8D63-4DF1-A4F2-8881172C1FE6}.Release|Any CPU.Build.0 = Release|Any CPU
- {E6A23627-8D63-4DF1-A4F2-8881172C1FE6}.Release|x64.ActiveCfg = Release|Any CPU
- {E6A23627-8D63-4DF1-A4F2-8881172C1FE6}.Release|x64.Build.0 = Release|Any CPU
- {E6A23627-8D63-4DF1-A4F2-8881172C1FE6}.Release|x86.ActiveCfg = Release|Any CPU
- {E6A23627-8D63-4DF1-A4F2-8881172C1FE6}.Release|x86.Build.0 = Release|Any CPU
{9788C76F-658B-4441-88F8-22C6B86FAD27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9788C76F-658B-4441-88F8-22C6B86FAD27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9788C76F-658B-4441-88F8-22C6B86FAD27}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -8099,9 +8041,6 @@ Global
{898F7E0B-1671-42CB-9DFB-689AFF212ED3} = {FED63417-432B-49CD-AB4B-44ADA837C2E7}
{65EE0531-4533-407F-A9CA-2EBCDC444397} = {898F7E0B-1671-42CB-9DFB-689AFF212ED3}
{0B200A66-B809-4ED3-A790-CB1C2E80975E} = {017429CC-C5FB-48B4-9C46-034E29EE2F06}
- {B6118E15-C37A-4B05-B4DF-97FE99790417} = {0B200A66-B809-4ED3-A790-CB1C2E80975E}
- {D0ADA8EC-F431-43C8-A86E-FE6A1E906512} = {B6118E15-C37A-4B05-B4DF-97FE99790417}
- {95920BAA-46E6-44E6-A1AF-A23804F079D2} = {B6118E15-C37A-4B05-B4DF-97FE99790417}
{A4EECF29-6E66-4E7F-B781-A169B0C2AB29} = {0B200A66-B809-4ED3-A790-CB1C2E80975E}
{52433D20-35EA-48CC-BB4A-4DFE3023670B} = {A4EECF29-6E66-4E7F-B781-A169B0C2AB29}
{8562A154-B802-411B-897C-89621C4B05CB} = {0B200A66-B809-4ED3-A790-CB1C2E80975E}
@@ -8202,8 +8141,6 @@ Global
{7F87406C-A3C8-4139-A68D-E4C344294A67} = {D62AF49B-F9FE-4794-AC39-A473FF13CA81}
{1533E271-F61B-441B-8B74-59FB61DF0552} = {D62AF49B-F9FE-4794-AC39-A473FF13CA81}
{7E268085-1046-4362-80CB-2977FF826DCA} = {D62AF49B-F9FE-4794-AC39-A473FF13CA81}
- {A5CE25E9-89E1-4F2C-9B89-0C161707E700} = {B6118E15-C37A-4B05-B4DF-97FE99790417}
- {E6A23627-8D63-4DF1-A4F2-8881172C1FE6} = {B6118E15-C37A-4B05-B4DF-97FE99790417}
{7D2B0799-A634-42AC-AE77-5D167BA51389} = {562D5067-8CD8-4F19-BCBB-873204932C61}
{9788C76F-658B-4441-88F8-22C6B86FAD27} = {7D2B0799-A634-42AC-AE77-5D167BA51389}
{1970D5CD-D9A4-4673-A297-179BB04199F4} = {7D2B0799-A634-42AC-AE77-5D167BA51389}
diff --git a/eng/ProjectReferences.props b/eng/ProjectReferences.props
index c3889fa6050a..3afacb916146 100644
--- a/eng/ProjectReferences.props
+++ b/eng/ProjectReferences.props
@@ -69,7 +69,6 @@
-
diff --git a/src/Tools/Tools.slnf b/src/Tools/Tools.slnf
index 2ad3d135e415..36f3b9f8bf2e 100644
--- a/src/Tools/Tools.slnf
+++ b/src/Tools/Tools.slnf
@@ -16,10 +16,6 @@
"src\\Tools\\dotnet-sql-cache\\src\\dotnet-sql-cache.csproj",
"src\\Tools\\dotnet-user-secrets\\src\\dotnet-user-secrets.csproj",
"src\\Tools\\dotnet-user-secrets\\test\\dotnet-user-secrets.Tests.csproj",
- "src\\Tools\\dotnet-watch\\src\\dotnet-watch.csproj",
- "src\\Tools\\dotnet-watch\\BrowserRefresh\\src\\Microsoft.AspNetCore.Watch.BrowserRefresh.csproj",
- "src\\Tools\\dotnet-watch\\BrowserRefresh\\test\\Microsoft.AspNetCore.Watch.BrowserRefresh.Tests.csproj",
- "src\\Tools\\dotnet-watch\\test\\dotnet-watch.Tests.csproj",
"src\\Middleware\\StaticFiles\\src\\Microsoft.AspNetCore.StaticFiles.csproj",
"src\\Hosting\\TestHost\\src\\Microsoft.AspNetCore.TestHost.csproj"
]
diff --git a/src/Tools/dotnet-watch/BrowserRefresh/src/BrowserRefreshMiddleware.cs b/src/Tools/dotnet-watch/BrowserRefresh/src/BrowserRefreshMiddleware.cs
deleted file mode 100644
index 210b4f73e890..000000000000
--- a/src/Tools/dotnet-watch/BrowserRefresh/src/BrowserRefreshMiddleware.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Http.Features;
-using Microsoft.Extensions.Logging;
-using Microsoft.Net.Http.Headers;
-
-namespace Microsoft.AspNetCore.Watch.BrowserRefresh
-{
- public class BrowserRefreshMiddleware
- {
- private static readonly MediaTypeHeaderValue _textHtmlMediaType = new MediaTypeHeaderValue("text/html");
- private readonly RequestDelegate _next;
- private readonly ILogger _logger;
-
- public BrowserRefreshMiddleware(RequestDelegate next, ILogger logger) =>
- (_next, _logger) = (next, logger);
-
- public async Task InvokeAsync(HttpContext context)
- {
- // We only need to support this for requests that could be initiated by a browser.
- if (IsBrowserRequest(context))
- {
- // Use a custom StreamWrapper to rewrite output on Write/WriteAsync
- using var responseStreamWrapper = new ResponseStreamWrapper(context, _logger);
- var originalBodyFeature = context.Features.Get();
- context.Features.Set(new StreamResponseBodyFeature(responseStreamWrapper));
-
- try
- {
- await _next(context);
- }
- finally
- {
- context.Features.Set(originalBodyFeature);
- }
-
- if (responseStreamWrapper.IsHtmlResponse && _logger.IsEnabled(LogLevel.Debug))
- {
- if (responseStreamWrapper.ScriptInjectionPerformed)
- {
- Log.BrowserConfiguredForRefreshes(_logger);
- }
- else
- {
- Log.FailedToConfiguredForRefreshes(_logger);
- }
- }
- }
- else
- {
- await _next(context);
- }
- }
-
- internal static bool IsBrowserRequest(HttpContext context)
- {
- var request = context.Request;
- if (!HttpMethods.IsGet(request.Method) && !HttpMethods.IsPost(request.Method))
- {
- return false;
- }
-
- var typedHeaders = request.GetTypedHeaders();
- if (!(typedHeaders.Accept is IList acceptHeaders))
- {
- return false;
- }
-
- for (var i = 0; i < acceptHeaders.Count; i++)
- {
- if (acceptHeaders[i].IsSubsetOf(_textHtmlMediaType))
- {
- return true;
- }
- }
-
- return false;
- }
-
- internal static class Log
- {
- private static readonly Action _setupResponseForBrowserRefresh = LoggerMessage.Define(
- LogLevel.Debug,
- new EventId(1, "SetUpResponseForBrowserRefresh"),
- "Response markup is scheduled to include browser refresh script injection.");
-
- private static readonly Action _browserConfiguredForRefreshes = LoggerMessage.Define(
- LogLevel.Debug,
- new EventId(2, "BrowserConfiguredForRefreshes"),
- "Response markup was updated to include browser refresh script injection.");
-
- private static readonly Action _failedToConfigureForRefreshes = LoggerMessage.Define(
- LogLevel.Debug,
- new EventId(3, "FailedToConfiguredForRefreshes"),
- "Unable to configure browser refresh script injection on the response.");
-
- public static void SetupResponseForBrowserRefresh(ILogger logger) => _setupResponseForBrowserRefresh(logger, null);
- public static void BrowserConfiguredForRefreshes(ILogger logger) => _browserConfiguredForRefreshes(logger, null);
- public static void FailedToConfiguredForRefreshes(ILogger logger) => _failedToConfigureForRefreshes(logger, null);
- }
- }
-}
diff --git a/src/Tools/dotnet-watch/BrowserRefresh/src/BrowserScriptMiddleware.cs b/src/Tools/dotnet-watch/BrowserRefresh/src/BrowserScriptMiddleware.cs
deleted file mode 100644
index b90ae7591ddc..000000000000
--- a/src/Tools/dotnet-watch/BrowserRefresh/src/BrowserScriptMiddleware.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.Globalization;
-using System.IO;
-using System.Text;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Http;
-
-namespace Microsoft.AspNetCore.Watch.BrowserRefresh
-{
- ///
- /// Responds with the contennts of WebSocketScriptInjection.js with the stub WebSocket url replaced by the
- /// one specified by the launching app.
- ///
- public sealed class BrowserScriptMiddleware
- {
- private readonly byte[] _scriptBytes;
- private readonly string _contentLength;
-
- public BrowserScriptMiddleware(RequestDelegate next)
- : this(Environment.GetEnvironmentVariable("ASPNETCORE_AUTO_RELOAD_WS_ENDPOINT")!)
- {
- }
-
- internal BrowserScriptMiddleware(string webSocketUrl)
- {
- _scriptBytes = GetWebSocketClientJavaScript(webSocketUrl);
- _contentLength = _scriptBytes.Length.ToString(CultureInfo.InvariantCulture);
- }
-
- public async Task InvokeAsync(HttpContext context)
- {
- context.Response.Headers["Cache-Control"] = "no-store";
- context.Response.Headers["Content-Length"] = _contentLength;
- context.Response.Headers["Content-Type"] = "application/javascript; charset=utf-8";
-
- await context.Response.Body.WriteAsync(_scriptBytes.AsMemory(), context.RequestAborted);
- }
-
- internal static byte[] GetWebSocketClientJavaScript(string hostString)
- {
- var jsFileName = "Microsoft.AspNetCore.Watch.BrowserRefresh.WebSocketScriptInjection.js";
- using var reader = new StreamReader(typeof(WebSocketScriptInjection).Assembly.GetManifestResourceStream(jsFileName)!);
- var script = reader.ReadToEnd().Replace("{{hostString}}", hostString);
-
- return Encoding.UTF8.GetBytes(script);
- }
- }
-}
diff --git a/src/Tools/dotnet-watch/BrowserRefresh/src/HostingFilter.cs b/src/Tools/dotnet-watch/BrowserRefresh/src/HostingFilter.cs
deleted file mode 100644
index 68f32444b707..000000000000
--- a/src/Tools/dotnet-watch/BrowserRefresh/src/HostingFilter.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.Globalization;
-using Microsoft.AspNetCore.Builder;
-using Microsoft.AspNetCore.Hosting;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.DependencyInjection.Extensions;
-
-[assembly: HostingStartup(typeof(Microsoft.AspNetCore.Watch.BrowserRefresh.HostingStartup))]
-
-namespace Microsoft.AspNetCore.Watch.BrowserRefresh
-{
- internal sealed class HostingStartup : IHostingStartup, IStartupFilter
- {
- public void Configure(IWebHostBuilder builder)
- {
- builder.ConfigureServices(services => services.TryAddEnumerable(ServiceDescriptor.Singleton(this)));
- }
-
- public Action Configure(Action next)
- {
- return app =>
- {
- app.Map(WebSocketScriptInjection.WebSocketScriptUrl, app1 => app1.UseMiddleware());
- app.UseMiddleware();
- next(app);
- };
- }
- }
-}
diff --git a/src/Tools/dotnet-watch/BrowserRefresh/src/Microsoft.AspNetCore.Watch.BrowserRefresh.csproj b/src/Tools/dotnet-watch/BrowserRefresh/src/Microsoft.AspNetCore.Watch.BrowserRefresh.csproj
deleted file mode 100644
index 017eb2028c9d..000000000000
--- a/src/Tools/dotnet-watch/BrowserRefresh/src/Microsoft.AspNetCore.Watch.BrowserRefresh.csproj
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
- netcoreapp3.1
- false
- enable
- false
- true
- true
- false
-
-
-
-
-
-
-
-
diff --git a/src/Tools/dotnet-watch/BrowserRefresh/src/ResponseStreamWrapper.cs b/src/Tools/dotnet-watch/BrowserRefresh/src/ResponseStreamWrapper.cs
deleted file mode 100644
index ae5fcc6f2cc7..000000000000
--- a/src/Tools/dotnet-watch/BrowserRefresh/src/ResponseStreamWrapper.cs
+++ /dev/null
@@ -1,153 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-// Based on https://github.com/RickStrahl/Westwind.AspnetCore.LiveReload/blob/128b5f524e86954e997f2c453e7e5c1dcc3db746/Westwind.AspnetCore.LiveReload/ResponseStreamWrapper.cs
-
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Http;
-using Microsoft.Extensions.Logging;
-using Microsoft.Net.Http.Headers;
-
-namespace Microsoft.AspNetCore.Watch.BrowserRefresh
-{
- ///
- /// Wraps the Response Stream to inject the WebSocket HTML into
- /// an HTML Page.
- ///
- public class ResponseStreamWrapper : Stream
- {
- private static readonly MediaTypeHeaderValue _textHtmlMediaType = new MediaTypeHeaderValue("text/html");
- private readonly Stream _baseStream;
- private readonly HttpContext _context;
- private readonly ILogger _logger;
- private bool? _isHtmlResponse;
-
- public ResponseStreamWrapper(HttpContext context, ILogger logger)
- {
- _context = context;
- _baseStream = context.Response.Body;
- _logger = logger;
- }
-
- public override bool CanRead => false;
- public override bool CanSeek => false;
- public override bool CanWrite => true;
- public override long Length { get; }
- public override long Position { get; set; }
- public bool ScriptInjectionPerformed { get; private set; }
-
- public bool IsHtmlResponse => _isHtmlResponse ?? false;
-
- public override void Flush()
- {
- OnWrite();
- _baseStream.Flush();
- }
-
- public override Task FlushAsync(CancellationToken cancellationToken)
- {
- OnWrite();
- return _baseStream.FlushAsync(cancellationToken);
- }
-
- public override void Write(ReadOnlySpan buffer)
- {
- OnWrite();
- if (IsHtmlResponse && !ScriptInjectionPerformed)
- {
- ScriptInjectionPerformed = WebSocketScriptInjection.TryInjectLiveReloadScript(_baseStream, buffer);
- }
- else
- {
- _baseStream.Write(buffer);
- }
- }
-
- public override void WriteByte(byte value)
- {
- OnWrite();
- _baseStream.WriteByte(value);
- }
-
- public override void Write(byte[] buffer, int offset, int count)
- {
- OnWrite();
-
- if (IsHtmlResponse && !ScriptInjectionPerformed)
- {
- ScriptInjectionPerformed = WebSocketScriptInjection.TryInjectLiveReloadScript(_baseStream, buffer.AsSpan(offset, count));
- }
- else
- {
- _baseStream.Write(buffer, offset, count);
- }
- }
-
- public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- {
- OnWrite();
-
- if (IsHtmlResponse && !ScriptInjectionPerformed)
- {
- ScriptInjectionPerformed = await WebSocketScriptInjection.TryInjectLiveReloadScriptAsync(_baseStream, buffer.AsMemory(offset, count), cancellationToken);
- }
- else
- {
- await _baseStream.WriteAsync(buffer, offset, count, cancellationToken);
- }
- }
-
- public override async ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default)
- {
- OnWrite();
-
- if (IsHtmlResponse && !ScriptInjectionPerformed)
- {
- ScriptInjectionPerformed = await WebSocketScriptInjection.TryInjectLiveReloadScriptAsync(_baseStream, buffer, cancellationToken);
- }
- else
- {
- await _baseStream.WriteAsync(buffer, cancellationToken);
- }
- }
-
- private void OnWrite()
- {
- if (_isHtmlResponse.HasValue)
- {
- return;
- }
-
- var response = _context.Response;
-
- _isHtmlResponse =
- (response.StatusCode == StatusCodes.Status200OK || response.StatusCode == StatusCodes.Status500InternalServerError) &&
- MediaTypeHeaderValue.TryParse(response.ContentType, out var mediaType) &&
- mediaType.IsSubsetOf(_textHtmlMediaType) &&
- (!mediaType.Charset.HasValue || mediaType.Charset.Equals("utf-8", StringComparison.OrdinalIgnoreCase));
-
- if (_isHtmlResponse.Value)
- {
- BrowserRefreshMiddleware.Log.SetupResponseForBrowserRefresh(_logger);
-
- // Since we're changing the markup content, reset the content-length
- response.Headers.ContentLength = null;
- }
- }
-
- public override int Read(byte[] buffer, int offset, int count) => throw new NotSupportedException();
-
- public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
-
- public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
- => throw new NotSupportedException();
-
- public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default)
- => throw new NotSupportedException();
-
- public override void SetLength(long value) => throw new NotSupportedException();
- }
-}
diff --git a/src/Tools/dotnet-watch/BrowserRefresh/src/StartupHook.cs b/src/Tools/dotnet-watch/BrowserRefresh/src/StartupHook.cs
deleted file mode 100644
index f0dbc50e61fa..000000000000
--- a/src/Tools/dotnet-watch/BrowserRefresh/src/StartupHook.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-internal class StartupHook
-{
- public static void Initialize()
- {
- // This method exists to make startup hook load successfully. We do not need to do anything interesting here.
- }
-}
diff --git a/src/Tools/dotnet-watch/BrowserRefresh/src/WebSocketScriptInjection.cs b/src/Tools/dotnet-watch/BrowserRefresh/src/WebSocketScriptInjection.cs
deleted file mode 100644
index 43cb43c50ef5..000000000000
--- a/src/Tools/dotnet-watch/BrowserRefresh/src/WebSocketScriptInjection.cs
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.IO;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace Microsoft.AspNetCore.Watch.BrowserRefresh
-{
- ///
- /// Helper class that handles the HTML injection into
- /// a string or byte array.
- ///
- public static class WebSocketScriptInjection
- {
- private const string BodyMarker = "