dox_http_client 0.0.4
dox_http_client: ^0.0.4 copied to clipboard
Fast native HTTP client for Dart, with HTTP/1.1, HTTP/2, HTTPS and keep-alive. Rust owns the sockets and parses the answers through dart:ffi.
0.0.4 #
DoxHttpPackageClientnow passes all tests of the Dart team for clients ofpackage:http(http_client_conformance_tests), with each optional group on. The tests run in the CI of this package.DoxHttpClientResponse.reasonPhraseandDoxHttpClientStreamedResponse.reasonPhrase: the reason phrase of the status line, likeOK. It is null for an HTTP/2 answer. The adapter gives it asreasonPhraseof the response.maxRedirectsfor one request:send(..., maxRedirects: 2)andsendStreamed(..., maxRedirects: 2). The adapter usesmaxRedirectsof the request.- The client reads a header value that goes over more than one line (obs-fold). It gives the value as one line. Before, such an answer failed with
badResponse. - Fix: a request body stream that the client did not start to read was not canceled when the request failed or was aborted. A
close()of its sink did not complete. - Fix in
DoxHttpPackageClient:- A
StreamedRequestwith no bytes, for example aGET, went out withtransfer-encoding: chunked. It goes out with no body now. - A request after
close()failed with aStateError. It fails with aClientExceptionnow. - The message of a request with too many redirects is
Redirect limit exceeded, like the default client ofpackage:http.
- A
- The ABI version of the native library does not change.
0.0.3 #
DoxHttpClient.sendStreamed(abort: ...)stops a request when theabortfuture completes. The client closes the connection of the request.- Before the head of the answer, the request fails with the new
DoxHttpFailure.aborted. After it, the body gets that failure as an error event.
- Before the head of the answer, the request fails with the new
- Fix:
DoxHttpPackageClientdid not close the connection when theabortTriggerof a request completed before the head of the answer. The connection stayed open until the server answered. It closes now.
0.0.2 #
DoxHttpClient(lookup: ...)gives the addresses of a host name to the client. The client connects only to these addresses. Use it to refuse addresses, for example those of your own network when a user gives the URL.- New library
package:dox_http_client/http.dartwithDoxHttpPackageClient. It is aClientof package:http that sends its requests through aDoxHttpClient. Give it to a package that takes anhttp.Client.Request,StreamedRequest,MultipartRequestandAbortableRequestwork. The answer body is a stream.- A failure is a
DoxHttpPackageClientException: aClientExceptionofpackage:httpthat is also aDoxHttpClientException. - A request with a body does not follow redirects.
maxRedirectsandpersistentConnectionof a request have no effect. - The package has a new dependency:
http. An app that does not import the new library does not get its code.
- HTTP/2. On an
https://URL, the client asks for HTTP/2 during the TLS handshake (ALPN) and uses it when the server has it. If not, it uses HTTP/1.1.- The requests to one HTTP/2 server share one connection. A request that fails or gets a timeout stops only its stream. Requests that start at the same time to a new server can open more than one connection.
send,sendStreamedand the other methods do not change. Streamed bodies use the flow control of HTTP/2: when the listener pauses, the server stops to send.- A request that the server did not work on (a refused stream, or a GOAWAY frame for an earlier stream) is sent again one time, for each method. When the connection closes before the head of an answer, only
GET,HEAD,PUT,DELETE,OPTIONSandTRACEare sent again. A request with a body stream is never sent again. DoxHttpClient(http2: false)uses HTTP/1.1 only.- The native library does the chunked framing of a request body stream now. The ABI version of the native library is 4.
- The fuzz target also gives random bytes to the HTTP/2 connection and to the HPACK decoder.
DoxHttpClient.sendStreamedsends a request with a body stream and gives the answer body as a stream. The memory stays small for bodies of many GB.- The answer body is
DoxHttpClientStreamedResponse.body. The new base classDoxHttpClientResponseHeadhasurl,statusCode,headersandheader(name). - The client reads a maximum of about 512 KiB ahead. When the listener pauses, the client stops to read the connection. When you cancel the body, the client closes the connection.
- The request
bodyis aStream<List<int>>.contentLengthsets thecontent-lengthheader. Without it, the client sends the body chunked. The client pauses the stream while more than 256 KiB wait to go out. timeoutis for the time until the head of the answer is there. With a body stream, the timeout starts again each time bytes of the body go out.- A gzip or brotli body is decoded in parts.
maxResponseSizeis the limit for the decoded bytes. - A failure after the head is an error event on the body stream.
- A request with no body follows redirects. A request with a body stream does not follow them and is sent only once.
- If the server answers before the whole body went out, the client cancels the upload and does not use the connection again.
- New
DoxHttpFailure.badRequestBody: the body stream gave more or fewer bytes thancontentLength. - The records between Dart and the native library have a kind, so the answers of requests that are not streamed are as cheap as before.
- The answer body is
- The client follows redirects (status 301, 302, 303, 307 and 308). One request follows a maximum of 5 redirects, then it fails with the new
DoxHttpFailure.tooManyRedirects.followRedirects(for the client or for onesendcall) andmaxRedirectschange this.- A 303 redirect changes the method to
GET. A 301 or 302 redirect changesPOSTtoGET. A 307 or 308 redirect keeps the method and the body. - The
authorization,cookie,proxy-authorizationandhostheaders do not go to a different server. - The timeout of a request includes its redirects.
DoxHttpClientResponse.urlis the URL that gave the answer.- The client sends
accept-encoding: gzip, brand decodes a gzip or brotli answer body in Rust.- A decoded answer has no
content-encodingheader and nocontent-lengthheader. maxResponseSizeis the limit for the decoded body.- A request with its own
accept-encodingheader or with arangeheader gets the body as the server sent it. - The native library has two more crates: flate2 and brotli-decompressor.
- A decoded answer has no
0.0.1 #
- First version.
DoxHttpClientis an HTTP client for calls to other servers. Rust owns the sockets and reads the answers on the thread of the isolate.get,head,post,put,patch,deleteandsendreturn aDoxHttpClientResponsewithstatusCode,body,bodyBytes,headersandheader(name).- HTTP/1.1 with keep-alive: the client keeps its connections open and uses them again. Chunked answers, answers that end with the connection, IPv4, IPv6 and host names are supported. When the first address of a host name does not accept the connection, the client tries the next address.
- HTTPS with TLS 1.2 and TLS 1.3 (rustls). The client trusts the root certificates of Mozilla, which are in the library.
trustedCertificatesadds your own certificates as PEM text. - A request fails with a
DoxHttpClientExceptionwhen no answer comes.failuregives the cause as aDoxHttpFailure. - The default timeout of a request is 30 seconds. Set
timeoutfor the client or for one request.Duration.zerois no timeout. - A connection with no request for
idleTimeout(default 15 seconds) closes.Duration.zerokeeps idle connections open. maxConnectionsPerHostandmaxResponseSizeare off by default.- Before a kept connection gets the next request, the client reads it. If the server closed it or sent bytes that nobody asked for, the client closes it and uses a different connection.
- The client does not do these things: HTTP/2, redirects, compressed bodies and streamed bodies.
- The package has its own native library. Its functions start with
dox_client_, so an app can load it together with the library ofdox_http_native. - A build from source needs a C compiler, because the TLS library compiles C code and assembly code. The ready-built libraries from the GitHub release do not need one.
- Fuzz target
client_responsefor the answer parser. THIRD_PARTY_NOTICESlists the licenses of the code and data in the native library. Each release also has it next to the libraries.