ResponseCompression style cleanup
This commit is contained in:
parent
ea04e34062
commit
665f2f8773
|
|
@ -1,12 +1,10 @@
|
|||
{
|
||||
"version": "1.1.0-*",
|
||||
"dependencies": {
|
||||
"Microsoft.AspNetCore.ResponseCompression": "0.1.0-*",
|
||||
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*"
|
||||
},
|
||||
"buildOptions": {
|
||||
"emitEntryPoint": true,
|
||||
"preserveCompilationContext": true
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"frameworks": {
|
||||
"net451": {},
|
||||
|
|
|
|||
|
|
@ -46,31 +46,21 @@ namespace Microsoft.AspNetCore.ResponseCompression
|
|||
}
|
||||
}
|
||||
|
||||
public override bool CanRead => _bodyOriginalStream.CanRead;
|
||||
public override bool CanRead => false;
|
||||
|
||||
public override bool CanSeek => _bodyOriginalStream.CanSeek;
|
||||
public override bool CanSeek => false;
|
||||
|
||||
public override bool CanWrite => _bodyOriginalStream.CanWrite;
|
||||
|
||||
public override long Length
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
get { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
get { throw new NotSupportedException(); }
|
||||
set { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
|
|
@ -169,16 +159,16 @@ namespace Microsoft.AspNetCore.ResponseCompression
|
|||
{
|
||||
if (!_compressionChecked)
|
||||
{
|
||||
_compressionChecked = true;
|
||||
|
||||
if (IsCompressable())
|
||||
{
|
||||
_response.Headers[HeaderNames.ContentEncoding] = _compressionProvider.EncodingName;
|
||||
_response.Headers.Remove(HeaderNames.ContentMD5); // Reset the MD5 because the content changed.
|
||||
_response.Headers.Append(HeaderNames.ContentEncoding, _compressionProvider.EncodingName);
|
||||
_response.Headers.Remove(HeaderNames.ContentMD5); // Reset the MD5 because the content changed.
|
||||
_response.Headers.Remove(HeaderNames.ContentLength);
|
||||
|
||||
_compressionStream = _compressionProvider.CreateStream(_bodyOriginalStream);
|
||||
}
|
||||
|
||||
_compressionChecked = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ namespace Microsoft.AspNetCore.ResponseCompression
|
|||
{
|
||||
throw new ArgumentException($"{nameof(options.Value.ShouldCompressResponse)} is not provided in argument {nameof(options)}");
|
||||
}
|
||||
|
||||
_shouldCompressResponse = options.Value.ShouldCompressResponse;
|
||||
|
||||
_next = next;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests
|
|||
private const string TextPlain = "text/plain";
|
||||
|
||||
[Fact]
|
||||
public void Options_NullShouldCompressResponse()
|
||||
public void Options_NullShouldCompressResponse_Throws()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
|
|
@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void Options_EmptyProviderList()
|
||||
public void Options_EmptyProviderList_Throws()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
{
|
||||
|
|
@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Request_Uncompressed()
|
||||
public async Task Request_NoAcceptEncoding_Uncompressed()
|
||||
{
|
||||
var response = await InvokeMiddleware(100, requestAcceptEncodings: null, responseType: TextPlain);
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Request_CompressGzip()
|
||||
public async Task Request_AcceptGzipDeflate_ComrpessedGzip()
|
||||
{
|
||||
var response = await InvokeMiddleware(100, requestAcceptEncodings: new string[] { "gzip", "deflate" }, responseType: TextPlain);
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Request_CompressUnknown()
|
||||
public async Task Request_AcceptUnknown_NotCompressed()
|
||||
{
|
||||
var response = await InvokeMiddleware(100, requestAcceptEncodings: new string[] { "unknown" }, responseType: TextPlain);
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Request_CompressStar()
|
||||
public async Task Request_AcceptStar_Compressed()
|
||||
{
|
||||
var response = await InvokeMiddleware(100, requestAcceptEncodings: new string[] { "*" }, responseType: TextPlain);
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Request_CompressIdentity()
|
||||
public async Task Request_AcceptIdentity_NotCompressed()
|
||||
{
|
||||
var response = await InvokeMiddleware(100, requestAcceptEncodings: new string[] { "identity" }, responseType: TextPlain);
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests
|
|||
[InlineData(new string[] { "identity;q=0.5", "gzip;q=1" }, 24)]
|
||||
[InlineData(new string[] { "identity;q=0", "gzip;q=0.8" }, 24)]
|
||||
[InlineData(new string[] { "identity;q=0.5", "gzip" }, 24)]
|
||||
public async Task Request_CompressQuality_Compressed(string[] acceptEncodings, int expectedBodyLength)
|
||||
public async Task Request_AcceptWithHigherCompressionQuality_Compressed(string[] acceptEncodings, int expectedBodyLength)
|
||||
{
|
||||
var response = await InvokeMiddleware(100, requestAcceptEncodings: acceptEncodings, responseType: TextPlain);
|
||||
|
||||
|
|
@ -107,7 +107,7 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests
|
|||
|
||||
[Theory]
|
||||
[InlineData(new string[] { "gzip;q=0.5", "identity;q=0.8" }, 100)]
|
||||
public async Task Request_CompressQuality_NotCompressed(string[] acceptEncodings, int expectedBodyLength)
|
||||
public async Task Request_AcceptWithhigherIdentityQuality_NotCompressed(string[] acceptEncodings, int expectedBodyLength)
|
||||
{
|
||||
var response = await InvokeMiddleware(100, requestAcceptEncodings: acceptEncodings, responseType: TextPlain);
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Request_UnauthorizedMimeType()
|
||||
public async Task Response_UnauthorizedMimeType_NotCompressed()
|
||||
{
|
||||
var response = await InvokeMiddleware(100, requestAcceptEncodings: new string[] { "gzip" }, responseType: "text/html");
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Request_ResponseWithContentRange()
|
||||
public async Task Response_WithContentRange_NotCompressed()
|
||||
{
|
||||
var response = await InvokeMiddleware(50, requestAcceptEncodings: new string[] { "gzip" }, responseType: TextPlain, addResponseAction: (r) =>
|
||||
{
|
||||
|
|
@ -134,7 +134,7 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Request_ResponseWithContentEncodingAlreadySet()
|
||||
public async Task Response_WithContentEncodingAlreadySet_NotCompressed()
|
||||
{
|
||||
var otherContentEncoding = "something";
|
||||
|
||||
|
|
@ -151,7 +151,7 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests
|
|||
[Theory]
|
||||
[InlineData(false, 100)]
|
||||
[InlineData(true, 24)]
|
||||
public async Task Request_Https(bool enableHttps, int expectedLength)
|
||||
public async Task Request_Https_CompressedIfEnabled(bool enableHttps, int expectedLength)
|
||||
{
|
||||
var options = new ResponseCompressionOptions()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests
|
|||
private const string TextPlain = "text/plain";
|
||||
|
||||
[Fact]
|
||||
public void CreateShouldCompressResponseDelegate_NullMimeTypes()
|
||||
public void CreateShouldCompressResponseDelegate_NullMimeTypes_Throws()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() =>
|
||||
{
|
||||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateShouldCompressResponseDelegate_Empty()
|
||||
public void CreateShouldCompressResponseDelegate_Empty_DontCompress()
|
||||
{
|
||||
var httpContext = new DefaultHttpContext();
|
||||
httpContext.Response.ContentType = TextPlain;
|
||||
|
|
@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests
|
|||
[InlineData("text/plain")]
|
||||
[InlineData("text/plain; charset=ISO-8859-4")]
|
||||
[InlineData("text/plain ; charset=ISO-8859-4")]
|
||||
public void CreateShouldCompressResponseDelegate_True(string contentType)
|
||||
public void CreateShouldCompressResponseDelegate_WithCharset_Compress(string contentType)
|
||||
{
|
||||
var httpContext = new DefaultHttpContext();
|
||||
httpContext.Response.ContentType = contentType;
|
||||
|
|
@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests
|
|||
[InlineData("")]
|
||||
[InlineData("text/plain2")]
|
||||
[InlineData("text/PLAIN")]
|
||||
public void CreateShouldCompressResponseDelegate_False(string contentType)
|
||||
public void CreateShouldCompressResponseDelegate_OtherContentTypes_NoMatch(string contentType)
|
||||
{
|
||||
var httpContext = new DefaultHttpContext();
|
||||
httpContext.Response.ContentType = contentType;
|
||||
|
|
|
|||
Loading…
Reference in New Issue