Changelog

New TIdHTTP functionality for protocol upgrading

A bug has been fixed where TIdHTTP would get stuck if it receives a 101 response (Switching Protocols) from an HTTP server. When 101 is received, TIdHTTP now exits immediately, and leaves the IOHandler open, allowing the caller to then use the IOHandler to continue performing I/O with the new protocol that has been switched to. For instance, this can be used to perform a WebSocket handshake over HTTP/S, and then use the IOHandler for subsequent WebSocket processing, eg.

IdHTTP1.Request.Connection := 'Upgrade';
IdHTTP1.Request.CustomHeaders.Values['Upgrade'] := 'websocket';
IdHTTP1.Request.CustomHeaders.Values['Sec-WebSocket-Key'] := '...';
IdHTTP1.Request.CustomHeaders.Values['Origin'] := '...';
IdHTTP1.Request.CustomHeaders.Values['Sec-WebSocket-Protocol'] := '...';
IdHTTP1.Request.CustomHeaders.Values['Sec-WebSocket-Version'] := '...';
IdHTTP1.Get('https://server/resource');
if IdHTTP1.Response.ResponseCode = 101 then
begin
  // Upgrade was accepted, use IdHTTP1.IOHandler to process WebSocket packets as needed ...
end else
begin
  // Upgrade was not accepted ...
end;