ktor icon indicating copy to clipboard operation
ktor copied to clipboard

KTOR-735 Support WinHTTP engine

Open dtretyakov opened this issue 3 years ago • 2 comments

This change brings support of new Windows engine built on top of WinHTTP library. It supports HTTP 1.x/2 and WebSocket protocols.

Subsystem Client, native windows engine.

Motivation Fixes #671 WinHTTP API allows using native HTTP client without need to include additional DLLs. Also, it allows using certificate stored in Windows Certificates store.

Solution

We’re using WinHTTP in asynchronous working mode. In such mode notifications about operation results are delivered via status callback. The library supports both HTTP request processing as well as WebSockets protocol.

In HTTP engine we are using the following abstractions:

  • WinHttpSession - create once per HTTP engine and allows configuring common settings like timeouts.
  • WinHttpConnect - represents connection to HTTP host. In our case it also stores list of callbacks for coroutine continuations.
  • WinHttpRequest - allows writing/reading request and response messages.
  • WinHttpRequestProducer - handles request body writing. Allows using chunked body encoding.
  • WinHttpWebSocket - represents WebSocket session. It's created from WinHttpRequest by closing original request and keeping WinHttpConnection open.

WinHTTP allows specifying connect and socket (send/receive) timeouts. Request timeout is handled by corresponding Ktor plugin.

Notes: WinHTTP is strict regarding Content-Length header validation in HTTP 1.x requests and requires using Transfer-Encoding: chunked request body if body length is unknown, e.g. when it's stream or channel based. In such cases we’re trying to use system encoding (modern Windows 10+ OS) or we're using fallback to manual chunks writing.

In case of failures we're converting error codes into human readable messages by using FormatMessage function.

dtretyakov avatar Jul 20 '22 07:07 dtretyakov

At first we need to check tests in CI build.

dtretyakov avatar Jul 20 '22 07:07 dtretyakov

Any progress?

ArcticLampyrid avatar Sep 14 '22 02:09 ArcticLampyrid

Any update on this?

Zxilly avatar Oct 10 '22 09:10 Zxilly

Please reopen it into main branch.

rsinukov avatar Nov 04 '22 12:11 rsinukov

Any further update on this?

Zxilly avatar Nov 10 '22 18:11 Zxilly