You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2019/06/21 23:05:12 UTC

[thrift] branch master updated: THRIFT-4894 Enable automatic content encoding handling for gzip, deflate in the WinHTTP client Client: Delphi Patch: Jens Geyer

This is an automated email from the ASF dual-hosted git repository.

jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new 19505c3  THRIFT-4894 Enable automatic content encoding handling for gzip,deflate in the WinHTTP client Client: Delphi Patch: Jens Geyer
19505c3 is described below

commit 19505c3de3f235b71da46b971c3ce38d59db1f22
Author: Jens Geyer <je...@apache.org>
AuthorDate: Sat Jun 22 00:59:54 2019 +0200

    THRIFT-4894 Enable automatic content encoding handling for gzip,deflate in the WinHTTP client
    Client: Delphi
    Patch: Jens Geyer
---
 lib/delphi/src/Thrift.Transport.WinHTTP.pas |  3 +++
 lib/delphi/src/Thrift.WinHTTP.pas           | 28 ++++++++++++++++++++++++++--
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/lib/delphi/src/Thrift.Transport.WinHTTP.pas b/lib/delphi/src/Thrift.Transport.WinHTTP.pas
index 540865f..262e38f 100644
--- a/lib/delphi/src/Thrift.Transport.WinHTTP.pas
+++ b/lib/delphi/src/Thrift.Transport.WinHTTP.pas
@@ -166,6 +166,9 @@ begin
       Result.AddRequestHeader( pair.Key +': '+ pair.Value, WINHTTP_ADDREQ_FLAG_ADD);
     end;
 
+    // enable automatic gzip,deflate decompression
+    result.EnableAutomaticContentDecompression(TRUE);
+
     // AutoProxy support
     info := TErrorInfo.AutoProxy;
     result.TryAutoProxy( FUri);
diff --git a/lib/delphi/src/Thrift.WinHTTP.pas b/lib/delphi/src/Thrift.WinHTTP.pas
index 8179fae..8d677dd 100644
--- a/lib/delphi/src/Thrift.WinHTTP.pas
+++ b/lib/delphi/src/Thrift.WinHTTP.pas
@@ -305,9 +305,11 @@ const
   WINHTTP_OPTION_SERVER_SPN_USED = 106;
   WINHTTP_OPTION_PROXY_SPN_USED = 107;
   WINHTTP_OPTION_SERVER_CBT = 108;
+  // options for newer WinHTTP versions
+  WINHTTP_OPTION_DECOMPRESSION = 118;
   //
   WINHTTP_FIRST_OPTION = WINHTTP_OPTION_CALLBACK;
-  WINHTTP_LAST_OPTION = WINHTTP_OPTION_SERVER_CBT;
+  //WINHTTP_LAST_OPTION = WINHTTP_OPTION_SERVER_CBT;
 
   WINHTTP_OPTION_USERNAME = $1000;
   WINHTTP_OPTION_PASSWORD = $1001;
@@ -368,6 +370,12 @@ const
   WINHTTP_AUTH_TARGET_SERVER     = $00000000;
   WINHTTP_AUTH_TARGET_PROXY      = $00000001;
 
+  // options for WINHTTP_OPTION_DECOMPRESSION
+  WINHTTP_DECOMPRESSION_FLAG_GZIP    = $00000001;
+  WINHTTP_DECOMPRESSION_FLAG_DEFLATE = $00000002;
+  WINHTTP_DECOMPRESSION_FLAG_ALL     = WINHTTP_DECOMPRESSION_FLAG_GZIP
+                                    or WINHTTP_DECOMPRESSION_FLAG_DEFLATE;
+
   // values for WINHTTP_OPTION_SECURITY_FLAGS
 
   // query only
@@ -478,12 +486,13 @@ type
   IWinHTTPConnection = interface;
 
   IWinHTTPRequest = interface
-    ['{0B7D095E-BB3D-4444-8686-5536E7D6437B}']
+    ['{F65952F2-2F3B-47DC-B524-F1694E6D2AD7}']
     function  Handle : HINTERNET;
     function  Connection : IWinHTTPConnection;
     function  AddRequestHeader( const aHeader : string; const addflag : DWORD = WINHTTP_ADDREQ_FLAG_ADD) : Boolean;
     function  SetTimeouts( const aResolveTimeout, aConnectTimeout, aSendTimeout, aReceiveTimeout : Int32) : Boolean;
     procedure TryAutoProxy( const aUrl : string);
+    procedure EnableAutomaticContentDecompression( const aEnable : Boolean);
     function  SendRequest( const pBuf : Pointer; const dwBytes : DWORD; const dwExtra : DWORD = 0) : Boolean;
     function  WriteExtraData( const pBuf : Pointer; const dwBytes : DWORD) : DWORD;
     function  FlushAndReceiveResponse : Boolean;
@@ -601,6 +610,7 @@ type
     function  AddRequestHeader( const aHeader : string; const addflag : DWORD = WINHTTP_ADDREQ_FLAG_ADD) : Boolean;
     function  SetTimeouts( const aResolveTimeout, aConnectTimeout, aSendTimeout, aReceiveTimeout : Int32) : Boolean;
     procedure TryAutoProxy( const aUrl : string);
+    procedure EnableAutomaticContentDecompression( const aEnable : Boolean);
     function  SendRequest( const pBuf : Pointer; const dwBytes : DWORD; const dwExtra : DWORD = 0) : Boolean;
     function  WriteExtraData( const pBuf : Pointer; const dwBytes : DWORD) : DWORD;
     function  FlushAndReceiveResponse : Boolean;
@@ -1033,6 +1043,20 @@ begin
 end;
 
 
+procedure TWinHTTPRequestImpl.EnableAutomaticContentDecompression( const aEnable : Boolean);
+// Enable automatic gzip,deflate decompression on systems that support this option
+// From the docs: WinHTTP will automatically set an appropriate Accept-Encoding header,
+// overriding any value supplied by the caller -> we don't have to do this
+// Available on Win 8.1 or higher
+var value : DWORD;
+begin
+  if aEnable
+  then value := WINHTTP_DECOMPRESSION_FLAG_ALL
+  else value := 0;
+
+  // ignore returned value, the option is not supported with older WinHTTP versions
+  WinHttpSetOption( Handle, WINHTTP_OPTION_DECOMPRESSION, @value, SizeOf(DWORD));
+end;
 
 
 function TWinHTTPRequestImpl.SendRequest( const pBuf : Pointer; const dwBytes, dwExtra : DWORD) : Boolean;