mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-06 18:35:19 +00:00
THRIFT-4217 HttpClient should support gzip and deflate
Client: C# Patch: Jens Geyer
This commit is contained in:
parent
695115952d
commit
197b062993
31
lib/csharp/src/Net35/ExtensionsNet35.cs
Normal file
31
lib/csharp/src/Net35/ExtensionsNet35.cs
Normal 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
|
||||
|
@ -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" />
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user