From 1d0778352234031c784006796e54c37ccc70855d Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Wed, 28 Feb 2018 15:19:08 +0000 Subject: [PATCH] Use "application/wasm" media type for .wasm files to enable streaming compilation --- .../Server/Startup.cs | 8 +++++-- .../BlazorAppBuilderExtensions.cs | 3 +-- .../BlazorOptions.cs | 5 ++--- .../WasmMediaTypeNames.cs | 22 +++++++++++++++++++ 4 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Blazor.Server/WasmMediaTypeNames.cs diff --git a/src/Microsoft.AspNetCore.Blazor.Cli/Server/Startup.cs b/src/Microsoft.AspNetCore.Blazor.Cli/Server/Startup.cs index cc36119c31..8cece4d4ab 100644 --- a/src/Microsoft.AspNetCore.Blazor.Cli/Server/Startup.cs +++ b/src/Microsoft.AspNetCore.Blazor.Cli/Server/Startup.cs @@ -1,6 +1,7 @@ // 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 Microsoft.AspNetCore.Blazor.Server; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; @@ -21,8 +22,11 @@ namespace Microsoft.AspNetCore.Blazor.Cli.Server services.AddRouting(); services.AddResponseCompression(options => { - options.MimeTypes = ResponseCompressionDefaults.MimeTypes - .Concat(new[] { MediaTypeNames.Application.Octet }); + options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] + { + MediaTypeNames.Application.Octet, + WasmMediaTypeNames.Application.Wasm + }); }); } diff --git a/src/Microsoft.AspNetCore.Blazor.Server/BlazorAppBuilderExtensions.cs b/src/Microsoft.AspNetCore.Blazor.Server/BlazorAppBuilderExtensions.cs index 3e25d4c7c9..3cc5f41f85 100644 --- a/src/Microsoft.AspNetCore.Blazor.Server/BlazorAppBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Blazor.Server/BlazorAppBuilderExtensions.cs @@ -7,7 +7,6 @@ using Microsoft.AspNetCore.StaticFiles; using Microsoft.Extensions.FileProviders; using System.IO; using System.Net.Mime; -using System.Reflection; namespace Microsoft.AspNetCore.Builder { @@ -81,7 +80,7 @@ namespace Microsoft.AspNetCore.Builder var result = new FileExtensionContentTypeProvider(); result.Mappings.Add(".dll", MediaTypeNames.Application.Octet); result.Mappings.Add(".mem", MediaTypeNames.Application.Octet); - result.Mappings.Add(".wasm", MediaTypeNames.Application.Octet); + result.Mappings.Add(".wasm", WasmMediaTypeNames.Application.Wasm); return result; } } diff --git a/src/Microsoft.AspNetCore.Blazor.Server/BlazorOptions.cs b/src/Microsoft.AspNetCore.Blazor.Server/BlazorOptions.cs index 6950cf0b0a..fb207f6faf 100644 --- a/src/Microsoft.AspNetCore.Blazor.Server/BlazorOptions.cs +++ b/src/Microsoft.AspNetCore.Blazor.Server/BlazorOptions.cs @@ -1,6 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Text; +// 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. namespace Microsoft.AspNetCore.Builder { diff --git a/src/Microsoft.AspNetCore.Blazor.Server/WasmMediaTypeNames.cs b/src/Microsoft.AspNetCore.Blazor.Server/WasmMediaTypeNames.cs new file mode 100644 index 0000000000..97b15a8392 --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor.Server/WasmMediaTypeNames.cs @@ -0,0 +1,22 @@ +// 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. + +namespace Microsoft.AspNetCore.Blazor.Server +{ + /// + /// Contains values for WASM-related media types. + /// + public static class WasmMediaTypeNames + { + /// + /// Contains values for WASM-related media types within the "application." namespace + /// + public static class Application + { + /// + /// The standard media type name for WebAssembly binary files. + /// + public const string Wasm = "application/wasm"; + } + } +}