Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GetGZipHeader method to provide OS-specific Gzip headers for unit… #629

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
68 changes: 50 additions & 18 deletions test/DotNetty.Codecs.Http.Tests/HttpContentCompressorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
namespace DotNetty.Codecs.Http.Tests
{
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using DotNetty.Buffers;
using DotNetty.Codecs.Compression;
Expand All @@ -13,6 +15,30 @@ namespace DotNetty.Codecs.Http.Tests

public sealed class HttpContentCompressorTest
{
// GZIPHeader
public static IEnumerable<object[]> GetGZipHeader()
{
string gzipHeaderHex = "";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
gzipHeaderHex = "1f8b080000000000000b";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
gzipHeaderHex = "1f8b0800000000000003";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
gzipHeaderHex = "1f8b0800000000000007";
}
else
{
gzipHeaderHex = "1f8b08000000000000ff";
}

yield return new object[] { gzipHeaderHex };
}

[Fact]
public void GetTargetContentEncoding()
{
Expand Down Expand Up @@ -56,8 +82,9 @@ public void GetTargetContentEncoding()
}
}

[Fact]
public void SplitContent()
[Theory]
[MemberData(nameof(GetGZipHeader))]
public void SplitContent(string gzipHeaderHex)
{
var ch = new EmbeddedChannel(new HttpContentCompressor());
ch.WriteInbound(NewRequest());
Expand All @@ -70,7 +97,7 @@ public void SplitContent()
AssertEncodedResponse(ch);

var chunk = ch.ReadOutbound<IHttpContent>();
Assert.Equal("1f8b080000000000000bf248cdc901000000ffff", ByteBufferUtil.HexDump(chunk.Content));
Assert.Equal(gzipHeaderHex + "f248cdc901000000ffff", ByteBufferUtil.HexDump(chunk.Content));
chunk.Release();

chunk = ch.ReadOutbound<IHttpContent>();
Expand All @@ -94,8 +121,9 @@ public void SplitContent()
Assert.Null(last);
}

[Fact]
public void ChunkedContent()
[Theory]
[MemberData(nameof(GetGZipHeader))]
public void ChunkedContent(string gzipHeaderHex)
{
var ch = new EmbeddedChannel(new HttpContentCompressor());
ch.WriteInbound(NewRequest());
Expand All @@ -111,7 +139,7 @@ public void ChunkedContent()
ch.WriteOutbound(new DefaultLastHttpContent(Unpooled.CopiedBuffer(Encoding.ASCII.GetBytes("orld"))));

var chunk = ch.ReadOutbound<IHttpContent>();
Assert.Equal("1f8b080000000000000bf248cdc901000000ffff", ByteBufferUtil.HexDump(chunk.Content));
Assert.Equal(gzipHeaderHex + "f248cdc901000000ffff", ByteBufferUtil.HexDump(chunk.Content));
chunk.Release();

chunk = ch.ReadOutbound<IHttpContent>();
Expand All @@ -135,8 +163,9 @@ public void ChunkedContent()
Assert.Null(last);
}

[Fact]
public void ChunkedContentWithTrailingHeader()
[Theory]
[MemberData(nameof(GetGZipHeader))]
public void ChunkedContentWithTrailingHeader(string gzipHeaderHex)
{
var ch = new EmbeddedChannel(new HttpContentCompressor());
ch.WriteInbound(NewRequest());
Expand All @@ -154,7 +183,7 @@ public void ChunkedContentWithTrailingHeader()
ch.WriteOutbound(content);

var chunk = ch.ReadOutbound<IHttpContent>();
Assert.Equal("1f8b080000000000000bf248cdc901000000ffff", ByteBufferUtil.HexDump(chunk.Content));
Assert.Equal(gzipHeaderHex + "f248cdc901000000ffff", ByteBufferUtil.HexDump(chunk.Content));
chunk.Release();

chunk = ch.ReadOutbound<IHttpContent>();
Expand All @@ -178,8 +207,9 @@ public void ChunkedContentWithTrailingHeader()
Assert.Null(last);
}

[Fact]
public void FullContentWithContentLength()
[Theory]
[MemberData(nameof(GetGZipHeader))]
public void FullContentWithContentLength(string gzipHeaderHex)
{
var ch = new EmbeddedChannel(new HttpContentCompressor());
ch.WriteInbound(NewRequest());
Expand All @@ -203,7 +233,7 @@ public void FullContentWithContentLength()

var c = ch.ReadOutbound<IHttpContent>();
observedLength += c.Content.ReadableBytes;
Assert.Equal("1f8b080000000000000bf248cdc9c9d75108cf2fca4901000000ffff", ByteBufferUtil.HexDump(c.Content));
Assert.Equal(gzipHeaderHex + "f248cdc9c9d75108cf2fca4901000000ffff", ByteBufferUtil.HexDump(c.Content));
c.Release();

c = ch.ReadOutbound<IHttpContent>();
Expand All @@ -220,8 +250,9 @@ public void FullContentWithContentLength()
Assert.Equal(contentLengthHeaderValue, observedLength);
}

[Fact]
public void FullContent()
[Theory]
[MemberData(nameof(GetGZipHeader))]
public void FullContent(string gzipHeaderHex)
{
var ch = new EmbeddedChannel(new HttpContentCompressor());
ch.WriteInbound(NewRequest());
Expand All @@ -233,7 +264,7 @@ public void FullContent()
AssertEncodedResponse(ch);

var chunk = ch.ReadOutbound<IHttpContent>();
Assert.Equal("1f8b080000000000000bf248cdc9c9d75108cf2fca4901000000ffff", ByteBufferUtil.HexDump(chunk.Content));
Assert.Equal(gzipHeaderHex + "f248cdc9c9d75108cf2fca4901000000ffff", ByteBufferUtil.HexDump(chunk.Content));
chunk.Release();

chunk = ch.ReadOutbound<IHttpContent>();
Expand All @@ -249,8 +280,9 @@ public void FullContent()
Assert.Null(last);
}

[Fact]
public void EmptySplitContent()
[Theory]
[MemberData(nameof(GetGZipHeader))]
public void EmptySplitContent(string gzipHeaderHex)
{
var ch = new EmbeddedChannel(new HttpContentCompressor());
ch.WriteInbound(NewRequest());
Expand All @@ -260,7 +292,7 @@ public void EmptySplitContent()

ch.WriteOutbound(EmptyLastHttpContent.Default);
var chunk = ch.ReadOutbound<IHttpContent>();
Assert.Equal("1f8b080000000000000b03000000000000000000", ByteBufferUtil.HexDump(chunk.Content));
Assert.Equal(gzipHeaderHex + "03000000000000000000", ByteBufferUtil.HexDump(chunk.Content));
chunk.Release();

chunk = ch.ReadOutbound<IHttpContent>();
Expand Down