THRIFT-5856 Client should validate HTTP status
Client: Delphi
Patch: Jens Geyer
diff --git a/lib/delphi/src/Thrift.Transport.MsxmlHTTP.pas b/lib/delphi/src/Thrift.Transport.MsxmlHTTP.pas
index 2cc3bfe..e3886a5 100644
--- a/lib/delphi/src/Thrift.Transport.MsxmlHTTP.pas
+++ b/lib/delphi/src/Thrift.Transport.MsxmlHTTP.pas
@@ -53,6 +53,8 @@
FCustomHeaders : IThriftDictionary<string,string>;
function CreateRequest: IXMLHTTPRequest;
+ class procedure EnsureSuccessHttpStatus( const aRequest : IXMLHTTPRequest);
+
strict protected
function GetIsOpen: Boolean; override;
procedure Open(); override;
@@ -255,6 +257,7 @@
ms.Position := 0;
xmlhttp.send( IUnknown( TStreamAdapter.Create( ms, soReference )));
FInputStream := nil;
+ EnsureSuccessHttpStatus(xmlhttp); // throws if not
FInputStream := TThriftStreamAdapterCOM.Create( IUnknown( xmlhttp.responseStream) as IStream);
ResetMessageSizeAndConsumedBytes;
UpdateKnownMessageSize( FInputStream.Size);
@@ -271,6 +274,20 @@
end;
+class procedure TMsxmlHTTPClientImpl.EnsureSuccessHttpStatus( const aRequest : IXMLHTTPRequest);
+var iStatus : Integer;
+ sText : string;
+begin
+ if aRequest = nil
+ then raise TTransportExceptionNotOpen.Create('Invalid HTTP request data');
+
+ iStatus := aRequest.status;
+ sText := aRequest.statusText;
+
+ if (200 > iStatus) or (iStatus > 299)
+ then raise TTransportExceptionEndOfFile.Create('HTTP '+IntToStr(iStatus)+' '+sText);
+end;
+
end.