THRIFT-5856 Client should validate HTTP status
Client: Delphi
Patch: Jens Geyer
diff --git a/lib/delphi/src/Thrift.Transport.WinHTTP.pas b/lib/delphi/src/Thrift.Transport.WinHTTP.pas
index 9deda4a..2d18ca1 100644
--- a/lib/delphi/src/Thrift.Transport.WinHTTP.pas
+++ b/lib/delphi/src/Thrift.Transport.WinHTTP.pas
@@ -51,6 +51,7 @@
 
     function CreateRequest: IWinHTTPRequest;
     function SecureProtocolsAsWinHTTPFlags : Cardinal;
+    class procedure EnsureSuccessHttpStatus( const aRequest : IWinHTTPRequest);
 
   strict private
     type
@@ -335,6 +336,7 @@
 
   // we're about to receive a new message, so reset everyting
   ResetMessageSizeAndConsumedBytes(-1);
+  EnsureSuccessHttpStatus(http);  // throws if not
   FInputStream := THTTPResponseStream.Create( http);
   if http.QueryTotalResponseSize( dwSize)  // FALSE indicates "no info available"
   then UpdateKnownMessageSize( dwSize);
@@ -349,6 +351,18 @@
 end;
 
 
+class procedure TWinHTTPClientImpl.EnsureSuccessHttpStatus( const aRequest : IWinHTTPRequest);
+var dwStatus : Cardinal;
+    sText : string;
+begin
+  if (aRequest <> nil)
+  then aRequest.QueryHttpStatus( dwStatus, sText)
+  else raise TTransportExceptionNotOpen.Create('Invalid HTTP request data');
+
+  if (200 > dwStatus) or (dwStatus > 299)
+  then raise TTransportExceptionEndOfFile.Create('HTTP '+UIntToStr(dwStatus)+' '+sText);
+end;
+
 { TWinHTTPClientImpl.THTTPResponseStream }
 
 constructor TWinHTTPClientImpl.THTTPResponseStream.Create( const aRequest : IWinHTTPRequest);