Skip to content
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
1 change: 1 addition & 0 deletions .spelling
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ brcrista
breakpoint
brianbunke
britishben
brotli
brucepay
bugfix
build.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,13 @@ Describe "Invoke-WebRequest tests" -Tags "Feature", "RequireAdminOnWindows" {
# Perform the following operation for Invoke-WebRequest
# gzip Returns gzip-encoded data.
# deflate Returns deflate-encoded data.
# brotli Returns brotli-encoded data.
# $dataEncodings = @("Chunked", "Compress", "Deflate", "GZip", "Identity")
# Note: These are the supported options, but we do not have a web service to test them all.
It "Invoke-WebRequest supports request that returns <DataEncoding>-encoded data." -TestCases @(
@{ DataEncoding = "gzip" }
@{ DataEncoding = "deflate" }
@{ DataEncoding = "brotli" }
) {
param($dataEncoding)
$uri = Get-WebListenerUrl -Test 'Compression' -TestValue $dataEncoding
Expand Down Expand Up @@ -2228,11 +2230,13 @@ Describe "Invoke-RestMethod tests" -Tags "Feature", "RequireAdminOnWindows" {
# Perform the following operation for Invoke-RestMethod
# gzip Returns gzip-encoded data.
# deflate Returns deflate-encoded data.
# brotli Returns brotli-encoded data.
# $dataEncodings = @("Chunked", "Compress", "Deflate", "GZip", "Identity")
# Note: These are the supported options, but we do not have a web service to test them all.
It "Invoke-RestMethod supports request that returns <DataEncoding>-encoded data." -TestCases @(
@{ DataEncoding = "gzip" }
@{ DataEncoding = "deflate" }
@{ DataEncoding = "brotli" }
) {
param($dataEncoding)
$uri = Get-WebListenerUrl -Test 'Compression' -TestValue $dataEncoding
Expand Down
33 changes: 33 additions & 0 deletions test/tools/WebListener/BrotliFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.IO;
using System.IO.Compression;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Filters;

namespace mvc.Controllers
{
internal sealed class BrotliFilter : ResultFilterAttribute
{
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
{
var httpContext = context.HttpContext;
using (var memoryStream = new MemoryStream())
{
var responseStream = httpContext.Response.Body;
httpContext.Response.Body = memoryStream;

await next();

using (var compressedStream = new BrotliStream(responseStream, CompressionLevel.Fastest))
{
httpContext.Response.Headers.Add("Content-Encoding", new[] { "br" });
memoryStream.Seek(0, SeekOrigin.Begin);
await memoryStream.CopyToAsync(compressedStream);
}
}
}
}
}
8 changes: 8 additions & 0 deletions test/tools/WebListener/Controllers/CompressionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public JsonResult Deflate()
return getController.Index();
}

[BrotliFilter]
public JsonResult Brotli()
{
var getController = new GetController();
getController.ControllerContext = this.ControllerContext;
return getController.Index();
}

public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
Expand Down
21 changes: 21 additions & 0 deletions test/tools/WebListener/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,27 @@ Response when certificate is not provided in request:
}
```

### /Compression/Brotli/

Returns the same results as the Get test with brotli compression.

```powershell
$uri = Get-WebListenerUrl -Test 'Compression' -TestValue 'Brotli'
Invoke-RestMethod -Uri $uri
```

```json
{
"args": {},
"origin": "127.0.0.1",
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT; Microsoft Windows 10.0.15063 ; en-US) PowerShell/6.0.0",
"Host": "localhost:8083"
},
"url": "http://localhost:8083/Compression/Brotli"
}
```

### /Compression/Deflate/

Returns the same results as the Get test with deflate compression.
Expand Down
1 change: 1 addition & 0 deletions test/tools/WebListener/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<li><a href="/Auth/Negotiate/">/Auth/Negotiate/</a> - Negotiate Authentication</li>
<li><a href="/Auth/NTLM/">/Auth/NTLM/</a> - NTLM Authentication</li>
<li><a href="/Cert/">/Cert/</a> - Client Certificate Details</li>
<li><a href="/Compression/Brotli/">/Compression/Brotli/</a> - Returns brotli compressed response</li>
<li><a href="/Compression/Deflate/">/Compression/Deflate/</a> - Returns deflate compressed response</li>
<li><a href="/Compression/GZip/">/Compression/Gzip/</a> - Returns gzip compressed response</li>
<li><a href="/Delay/">/Delay/{seconds}</a> - Delays response for <i>seconds</i> seconds.</li>
Expand Down