I am trying to communicate with Google Cloud Speech via gRPC from a Delphi 10.3.1 Windows client application. For this, the communication needs to be using http2 as protocol, and data needs to be transmitted 2-ways async.
Delphi includes TNetHTTPClient, which is used by TNetHTTPRequest for http communication. Using the debugger, I found that TWinHTTPClient in System.Net.HttpClient.Win.pas is used internally for the communication.
To add http2 support, I inserted 2 lines in TWinHTTPClient.DoExecuteRequest in System.Net.HttpClient.Win.pas, at line 1360:
LOptionValue := 1;//WINHTTP_PROTOCOL_FLAG_HTTP2;
WinHttpSetOption(LRequest.FWRequest, WINHTTP_OPTION_ENABLE_HTTP_PROTOCOL, @LOptionValue, sizeof(LOptionValue));
After adding the above code, the component is using http2, which I verified by calling Google Cloud Speech Sync Request endpoint via gRPC successfully.
However, my approach has two major disadvantages:
- It needs Delphi Source Code modification.
- It does not support async bidirectional transport of data, for which I think an event a la OnDataReceived that may be triggered without the connection being closed is necessary.
I tried to find a point where I could replace TNetHTTPClient by a modified component TMyNetHTTPClient, but I did not succeed.
So, the question is: how to create a TNetHTTPClient replacement, based on TWinHTTPClient, that supports http2 and implements OnDataReceived event without closing the connection?