THRIFT-4841 THTTPTransport relies on activeX component
Client: Delphi
Patch: Jens Geyer
This closes #1778
diff --git a/lib/delphi/src/Thrift.Transport.pas b/lib/delphi/src/Thrift.Transport.pas
index dad9ab7..1f8fdb0 100644
--- a/lib/delphi/src/Thrift.Transport.pas
+++ b/lib/delphi/src/Thrift.Transport.pas
@@ -29,9 +29,9 @@
Math,
Generics.Collections,
{$IFDEF OLD_UNIT_NAMES}
- ActiveX, msxml, WinSock, Sockets,
+ WinSock, Sockets,
{$ELSE}
- Winapi.ActiveX, Winapi.msxml, Winapi.WinSock,
+ Winapi.WinSock,
{$IFDEF OLD_SOCKETS}
Web.Win.Sockets,
{$ELSE}
@@ -41,6 +41,7 @@
Thrift.Collections,
Thrift.Exception,
Thrift.Utils,
+ Thrift.WinHTTP,
Thrift.Stream;
type
@@ -137,47 +138,6 @@
property CustomHeaders: IThriftDictionary<string,string> read GetCustomHeaders;
end;
- THTTPClientImpl = class( TTransportImpl, IHTTPClient)
- private
- FUri : string;
- FInputStream : IThriftStream;
- FOutputStream : IThriftStream;
- FDnsResolveTimeout : Integer;
- FConnectionTimeout : Integer;
- FSendTimeout : Integer;
- FReadTimeout : Integer;
- FCustomHeaders : IThriftDictionary<string,string>;
-
- function CreateRequest: IXMLHTTPRequest;
- protected
- function GetIsOpen: Boolean; override;
- procedure Open(); override;
- procedure Close(); override;
- function Read( const pBuf : Pointer; const buflen : Integer; off: Integer; len: Integer): Integer; override;
- procedure Write( const pBuf : Pointer; off, len : Integer); override;
- procedure Flush; override;
-
- procedure SetDnsResolveTimeout(const Value: Integer);
- function GetDnsResolveTimeout: Integer;
- procedure SetConnectionTimeout(const Value: Integer);
- function GetConnectionTimeout: Integer;
- procedure SetSendTimeout(const Value: Integer);
- function GetSendTimeout: Integer;
- procedure SetReadTimeout(const Value: Integer);
- function GetReadTimeout: Integer;
-
- function GetCustomHeaders: IThriftDictionary<string,string>;
- procedure SendRequest;
- property DnsResolveTimeout: Integer read GetDnsResolveTimeout write SetDnsResolveTimeout;
- property ConnectionTimeout: Integer read GetConnectionTimeout write SetConnectionTimeout;
- property SendTimeout: Integer read GetSendTimeout write SetSendTimeout;
- property ReadTimeout: Integer read GetReadTimeout write SetReadTimeout;
- property CustomHeaders: IThriftDictionary<string,string> read GetCustomHeaders;
- public
- constructor Create( const AUri: string);
- destructor Destroy; override;
- end;
-
IServerTransport = interface
['{C43B87ED-69EA-47C4-B77C-15E288252900}']
procedure Listen;
@@ -472,170 +432,6 @@
Self.Write( pBuf, 0, len);
end;
-{ THTTPClientImpl }
-
-constructor THTTPClientImpl.Create(const AUri: string);
-begin
- inherited Create;
- FUri := AUri;
-
- // defaults according to MSDN
- FDnsResolveTimeout := 0; // no timeout
- FConnectionTimeout := 60 * 1000;
- FSendTimeout := 30 * 1000;
- FReadTimeout := 30 * 1000;
-
- FCustomHeaders := TThriftDictionaryImpl<string,string>.Create;
- FOutputStream := TThriftStreamAdapterDelphi.Create( TMemoryStream.Create, True);
-end;
-
-function THTTPClientImpl.CreateRequest: IXMLHTTPRequest;
-var
- pair : TPair<string,string>;
- srvHttp : IServerXMLHTTPRequest;
-begin
- {$IF CompilerVersion >= 21.0}
- Result := CoServerXMLHTTP.Create;
- {$ELSE}
- Result := CoXMLHTTPRequest.Create;
- {$IFEND}
-
- // setting a timeout value to 0 (zero) means "no timeout" for that setting
- if Supports( result, IServerXMLHTTPRequest, srvHttp)
- then srvHttp.setTimeouts( DnsResolveTimeout, ConnectionTimeout, SendTimeout, ReadTimeout);
-
- Result.open('POST', FUri, False, '', '');
- Result.setRequestHeader( 'Content-Type', 'application/x-thrift');
- Result.setRequestHeader( 'Accept', 'application/x-thrift');
- Result.setRequestHeader( 'User-Agent', 'Delphi/IHTTPClient');
-
- for pair in FCustomHeaders do begin
- Result.setRequestHeader( pair.Key, pair.Value );
- end;
-end;
-
-destructor THTTPClientImpl.Destroy;
-begin
- Close;
- inherited;
-end;
-
-function THTTPClientImpl.GetDnsResolveTimeout: Integer;
-begin
- Result := FDnsResolveTimeout;
-end;
-
-procedure THTTPClientImpl.SetDnsResolveTimeout(const Value: Integer);
-begin
- FDnsResolveTimeout := Value;
-end;
-
-function THTTPClientImpl.GetConnectionTimeout: Integer;
-begin
- Result := FConnectionTimeout;
-end;
-
-procedure THTTPClientImpl.SetConnectionTimeout(const Value: Integer);
-begin
- FConnectionTimeout := Value;
-end;
-
-function THTTPClientImpl.GetSendTimeout: Integer;
-begin
- Result := FSendTimeout;
-end;
-
-procedure THTTPClientImpl.SetSendTimeout(const Value: Integer);
-begin
- FSendTimeout := Value;
-end;
-
-function THTTPClientImpl.GetReadTimeout: Integer;
-begin
- Result := FReadTimeout;
-end;
-
-procedure THTTPClientImpl.SetReadTimeout(const Value: Integer);
-begin
- FReadTimeout := Value;
-end;
-
-function THTTPClientImpl.GetCustomHeaders: IThriftDictionary<string,string>;
-begin
- Result := FCustomHeaders;
-end;
-
-function THTTPClientImpl.GetIsOpen: Boolean;
-begin
- Result := True;
-end;
-
-procedure THTTPClientImpl.Open;
-begin
- FOutputStream := TThriftStreamAdapterDelphi.Create( TMemoryStream.Create, True);
-end;
-
-procedure THTTPClientImpl.Close;
-begin
- FInputStream := nil;
- FOutputStream := nil;
-end;
-
-procedure THTTPClientImpl.Flush;
-begin
- try
- SendRequest;
- finally
- FOutputStream := nil;
- FOutputStream := TThriftStreamAdapterDelphi.Create( TMemoryStream.Create, True);
- ASSERT( FOutputStream <> nil);
- end;
-end;
-
-function THTTPClientImpl.Read( const pBuf : Pointer; const buflen : Integer; off: Integer; len: Integer): Integer;
-begin
- if FInputStream = nil then begin
- raise TTransportExceptionNotOpen.Create('No request has been sent');
- end;
-
- try
- Result := FInputStream.Read( pBuf, buflen, off, len)
- except
- on E: Exception
- do raise TTransportExceptionUnknown.Create(E.Message);
- end;
-end;
-
-procedure THTTPClientImpl.SendRequest;
-var
- xmlhttp : IXMLHTTPRequest;
- ms : TMemoryStream;
- a : TBytes;
- len : Integer;
-begin
- xmlhttp := CreateRequest;
-
- ms := TMemoryStream.Create;
- try
- a := FOutputStream.ToArray;
- len := Length(a);
- if len > 0 then begin
- ms.WriteBuffer( Pointer(@a[0])^, len);
- end;
- ms.Position := 0;
- xmlhttp.send( IUnknown( TStreamAdapter.Create( ms, soReference )));
- FInputStream := nil;
- FInputStream := TThriftStreamAdapterCOM.Create( IUnknown( xmlhttp.responseStream) as IStream);
- finally
- ms.Free;
- end;
-end;
-
-procedure THTTPClientImpl.Write( const pBuf : Pointer; off, len : Integer);
-begin
- FOutputStream.Write( pBuf, off, len);
-end;
-
{ TTransportException }
function TTransportException.GetType: TExceptionType;