THRIFT-4217 HttpClient should support gzip and deflate

Client: C#
Patch: Jens Geyer
This commit is contained in:
Jens Geyer 2017-05-31 10:35:00 +02:00
parent 695115952d
commit 197b062993
3 changed files with 46 additions and 10 deletions

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
#if (!NET45)
namespace Thrift
{
static class StreamExtensionsNet35
{
// CopyTo() has been added in 4.0
public static long CopyTo(this Stream source, Stream target)
{
byte[] buffer = new byte[8192]; // multiple of 4096
long nTotal = 0;
while (true)
{
int nRead = source.Read(buffer, 0, buffer.Length);
if (nRead <= 0) // done?
return nTotal;
target.Write(buffer, 0, nRead);
nTotal += nRead;
}
}
}
}
#endif

View File

@ -79,6 +79,7 @@
<ItemGroup>
<Compile Include="Collections\TCollections.cs" />
<Compile Include="Collections\THashSet.cs" />
<Compile Include="Net35\ExtensionsNet35.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Protocol\TAbstractBase.cs" />
<Compile Include="Protocol\TBase.cs" />

View File

@ -195,18 +195,22 @@ namespace Thrift.Transport
inputStream.Seek(0, 0);
}
foreach( var encoding in response.Headers.GetValues("Content-Encoding"))
var encodings = response.Headers.GetValues("Content-Encoding");
if (encodings != null)
{
switch(encoding)
foreach (var encoding in encodings)
{
case "gzip":
DecompressGZipped(ref inputStream);
break;
case "deflate":
DecompressDeflated(ref inputStream);
break;
default:
break;
switch (encoding)
{
case "gzip":
DecompressGZipped(ref inputStream);
break;
case "deflate":
DecompressDeflated(ref inputStream);
break;
default:
break;
}
}
}
}