forked from dotnet/AspNetDocs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
246 additions
and
246 deletions.
There are no files selected for viewing
38 changes: 19 additions & 19 deletions
38
aspnetcore/performance/response-compression/sample/CustomCompressionProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
using System.IO; | ||
using Microsoft.AspNetCore.ResponseCompression; | ||
|
||
namespace ResponseCompressionSample | ||
{ | ||
#region snippet1 | ||
public class CustomCompressionProvider : ICompressionProvider | ||
{ | ||
public string EncodingName => "mycustomcompression"; | ||
public bool SupportsFlush => true; | ||
|
||
public Stream CreateStream(Stream outputStream) | ||
{ | ||
// Create a custom compression stream wrapper here | ||
return outputStream; | ||
} | ||
} | ||
#endregion | ||
} | ||
using System.IO; | ||
using Microsoft.AspNetCore.ResponseCompression; | ||
|
||
namespace ResponseCompressionSample | ||
{ | ||
#region snippet1 | ||
public class CustomCompressionProvider : ICompressionProvider | ||
{ | ||
public string EncodingName => "mycustomcompression"; | ||
public bool SupportsFlush => true; | ||
|
||
public Stream CreateStream(Stream outputStream) | ||
{ | ||
// Create a custom compression stream wrapper here | ||
return outputStream; | ||
} | ||
} | ||
#endregion | ||
} |
14 changes: 7 additions & 7 deletions
14
aspnetcore/performance/response-compression/sample/LoremIpsum.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
namespace ResponseCompressionSample | ||
{ | ||
internal static class LoremIpsum | ||
{ | ||
internal const string Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi. Proin porttitor, orci nec nonummy molestie, enim est eleifend mi, non fermentum diam nisl sit amet erat. Duis semper. Duis arcu massa, scelerisque vitae, consequat in, pretium a, enim. Pellentesque congue. Ut in risus volutpat libero pharetra tempor. Cras vestibulum bibendum augue. Praesent egestas leo in pede. Praesent blandit odio eu enim. Pellentesque sed dui ut augue blandit sodales. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aliquam nibh. Mauris ac mauris sed pede pellentesque fermentum. Maecenas adipiscing ante non diam sodales hendrerit. Ut velit mauris, egestas sed, gravida nec, ornare ut, mi. Aenean ut orci vel massa suscipit pulvinar.Nulla sollicitudin.Fusce varius, ligula non tempus aliquam, nunc turpis ullamcorper nibh, in tempus sapien eros vitae ligula.Pellentesque rhoncus nunc et augue.Integer id felis.Curabitur aliquet pellentesque diam. Integer quis metus vitae elit lobortis egestas.Lorem ipsum dolor sit amet, consectetuer adipiscing elit.Morbi vel erat non mauris convallis vehicula.Nulla et sapien.Integer tortor tellus, aliquam faucibus, convallis id, congue eu, quam.Mauris ullamcorper felis vitae erat.Proin feugiat, augue non elementum posuere, metus purus iaculis lectus, et tristique ligula justo vitae magna. Aliquam convallis sollicitudin purus. Praesent aliquam, enim at fermentum mollis, ligula massa adipiscing nisl, ac euismod nibh nisl eu lectus. Fusce vulputate sem at sapien.Vivamus leo. Aliquam euismod libero eu enim.Nulla nec felis sed leo placerat imperdiet.Aenean suscipit nulla in justo.Suspendisse cursus rutrum augue. Nulla tincidunt tincidunt mi. Curabitur iaculis, lorem vel rhoncus faucibus, felis magna fermentum augue, et ultricies lacus lorem varius purus. Curabitur eu amet."; | ||
} | ||
} | ||
namespace ResponseCompressionSample | ||
{ | ||
internal static class LoremIpsum | ||
{ | ||
internal const string Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi. Proin porttitor, orci nec nonummy molestie, enim est eleifend mi, non fermentum diam nisl sit amet erat. Duis semper. Duis arcu massa, scelerisque vitae, consequat in, pretium a, enim. Pellentesque congue. Ut in risus volutpat libero pharetra tempor. Cras vestibulum bibendum augue. Praesent egestas leo in pede. Praesent blandit odio eu enim. Pellentesque sed dui ut augue blandit sodales. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aliquam nibh. Mauris ac mauris sed pede pellentesque fermentum. Maecenas adipiscing ante non diam sodales hendrerit. Ut velit mauris, egestas sed, gravida nec, ornare ut, mi. Aenean ut orci vel massa suscipit pulvinar.Nulla sollicitudin.Fusce varius, ligula non tempus aliquam, nunc turpis ullamcorper nibh, in tempus sapien eros vitae ligula.Pellentesque rhoncus nunc et augue.Integer id felis.Curabitur aliquet pellentesque diam. Integer quis metus vitae elit lobortis egestas.Lorem ipsum dolor sit amet, consectetuer adipiscing elit.Morbi vel erat non mauris convallis vehicula.Nulla et sapien.Integer tortor tellus, aliquam faucibus, convallis id, congue eu, quam.Mauris ullamcorper felis vitae erat.Proin feugiat, augue non elementum posuere, metus purus iaculis lectus, et tristique ligula justo vitae magna. Aliquam convallis sollicitudin purus. Praesent aliquam, enim at fermentum mollis, ligula massa adipiscing nisl, ac euismod nibh nisl eu lectus. Fusce vulputate sem at sapien.Vivamus leo. Aliquam euismod libero eu enim.Nulla nec felis sed leo placerat imperdiet.Aenean suscipit nulla in justo.Suspendisse cursus rutrum augue. Nulla tincidunt tincidunt mi. Curabitur iaculis, lorem vel rhoncus faucibus, felis magna fermentum augue, et ultricies lacus lorem varius purus. Curabitur eu amet."; | ||
} | ||
} |
44 changes: 22 additions & 22 deletions
44
aspnetcore/performance/response-compression/sample/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace ResponseCompressionSample | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var host = new WebHostBuilder() | ||
.ConfigureLogging(factory => | ||
{ | ||
factory.AddConsole(LogLevel.Debug); | ||
}) | ||
.UseKestrel() | ||
.UseStartup<Startup>() | ||
.Build(); | ||
|
||
host.Run(); | ||
} | ||
} | ||
} | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace ResponseCompressionSample | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var host = new WebHostBuilder() | ||
.ConfigureLogging(factory => | ||
{ | ||
factory.AddConsole(LogLevel.Debug); | ||
}) | ||
.UseKestrel() | ||
.UseStartup<Startup>() | ||
.Build(); | ||
|
||
host.Run(); | ||
} | ||
} | ||
} |
40 changes: 20 additions & 20 deletions
40
aspnetcore/performance/response-compression/sample/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
# Response compression sample application | ||
|
||
This sample illustrates the use of ASP.NET Core Response Compression Middleware to compress HTTP responses. The sample demonstrates Gzip and custom compression providers for text and image responses and shows how to add a MIME type for compression. | ||
|
||
## Examples in this sample | ||
* `GzipCompressionProvider` | ||
* `text/plain` | ||
* **/** - Lorem Ipsum text file response at 2,044 bytes that will compress to 927 bytes | ||
* **/testfile1kb.txt** - Text file response at 1,033 bytes that will compress to 47 bytes | ||
* **/trickle** - Response issued as single characters at 1 second intervals | ||
* `image/svg+xml` | ||
* **/banner.svg** - A Scalable Vector Graphics (SVG) image response at 9,707 bytes that will compress to 4,459 bytes | ||
* `CustomCompressionProvider`<br>Shows how to implement a custom compression provider for use with the middleware | ||
|
||
When the request includes the `Accept-Encoding` header, the sample adds a `Vary: Accept-Encoding` header to the response. The `Vary` header instructs caches to maintain multiple copies of the response based on alternative values of `Accept-Encoding`, so both a compressed (gzip) and uncompressed version will be stored in caches for systems that can either accept the compressed or the uncompressed response. | ||
|
||
## Using the sample | ||
1. Make a request using [Fiddler](http://www.telerik.com/fiddler), [Firebug](http://getfirebug.com/), or [Postman](https://www.getpostman.com/) to the application without an `Accept-Encoding` header and note the response payload, response size, and response headers. | ||
2. Add an `Accept-Encoding: gzip` header and note the compressed response size and response headers. You will see the response size drop and the `Content-Encoding: gzip` response header. When you look at the response body for the Lorem Ipsum or **testfile1kb.txt** response, you will see that the text has been compressed and is unreadable. | ||
3. Add an `Accept-Encoding: mycustomcompression` header and note the response headers. The `CustomCompressionProvider` is an empty implementation that doesn't actually compress the response, but you can create a custom compression stream wrapper for the `CreateStream()` method. | ||
# Response compression sample application | ||
|
||
This sample illustrates the use of ASP.NET Core Response Compression Middleware to compress HTTP responses. The sample demonstrates Gzip and custom compression providers for text and image responses and shows how to add a MIME type for compression. | ||
|
||
## Examples in this sample | ||
* `GzipCompressionProvider` | ||
* `text/plain` | ||
* **/** - Lorem Ipsum text file response at 2,044 bytes that will compress to 927 bytes | ||
* **/testfile1kb.txt** - Text file response at 1,033 bytes that will compress to 47 bytes | ||
* **/trickle** - Response issued as single characters at 1 second intervals | ||
* `image/svg+xml` | ||
* **/banner.svg** - A Scalable Vector Graphics (SVG) image response at 9,707 bytes that will compress to 4,459 bytes | ||
* `CustomCompressionProvider`<br>Shows how to implement a custom compression provider for use with the middleware | ||
|
||
When the request includes the `Accept-Encoding` header, the sample adds a `Vary: Accept-Encoding` header to the response. The `Vary` header instructs caches to maintain multiple copies of the response based on alternative values of `Accept-Encoding`, so both a compressed (gzip) and uncompressed version will be stored in caches for systems that can either accept the compressed or the uncompressed response. | ||
|
||
## Using the sample | ||
1. Make a request using [Fiddler](http://www.telerik.com/fiddler), [Firebug](http://getfirebug.com/), or [Postman](https://www.getpostman.com/) to the application without an `Accept-Encoding` header and note the response payload, response size, and response headers. | ||
2. Add an `Accept-Encoding: gzip` header and note the compressed response size and response headers. You will see the response size drop and the `Content-Encoding: gzip` response header. When you look at the response body for the Lorem Ipsum or **testfile1kb.txt** response, you will see that the text has been compressed and is unreadable. | ||
3. Add an `Accept-Encoding: mycustomcompression` header and note the response headers. The `CustomCompressionProvider` is an empty implementation that doesn't actually compress the response, but you can create a custom compression stream wrapper for the `CreateStream()` method. |
60 changes: 30 additions & 30 deletions
60
aspnetcore/performance/response-compression/sample/ResponseCompressionSample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net451;netcoreapp1.1</TargetFrameworks> | ||
<OutputType>Exe</OutputType> | ||
<!-- TODO remove rid when https://github.com/dotnet/sdk/issues/396 is resolved --> | ||
<RuntimeIdentifier Condition="'$(TargetFramework)'!='netcoreapp1.1'">win7-x64</RuntimeIdentifier> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="banner.svg;testfile1kb.txt" CopyToPublishDirectory="PreserveNewest" CopyToOutputDirectory="PreserveNewest" /> | ||
<EmbeddedResource Include="compiler\resources\**\*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="1.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.1' "> | ||
<PackageReference Include="Microsoft.NETCore.App" Version="1.1.0" /> | ||
</ItemGroup> | ||
|
||
<Target Name="CreateLogsFolder" AfterTargets="AfterPublish"> | ||
<MakeDir Directories="$(PublishDir)logs" Condition="!Exists('$(PublishDir)logs')" /> | ||
</Target> | ||
|
||
</Project> | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net451;netcoreapp1.1</TargetFrameworks> | ||
<OutputType>Exe</OutputType> | ||
<!-- TODO remove rid when https://github.com/dotnet/sdk/issues/396 is resolved --> | ||
<RuntimeIdentifier Condition="'$(TargetFramework)'!='netcoreapp1.1'">win7-x64</RuntimeIdentifier> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="banner.svg;testfile1kb.txt" CopyToPublishDirectory="PreserveNewest" CopyToOutputDirectory="PreserveNewest" /> | ||
<EmbeddedResource Include="compiler\resources\**\*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="1.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.1' "> | ||
<PackageReference Include="Microsoft.NETCore.App" Version="1.1.0" /> | ||
</ItemGroup> | ||
|
||
<Target Name="CreateLogsFolder" AfterTargets="AfterPublish"> | ||
<MakeDir Directories="$(PublishDir)logs" Condition="!Exists('$(PublishDir)logs')" /> | ||
</Target> | ||
|
||
</Project> |
Oops, something went wrong.