dox_http_native 3.0.0-alpha.3
dox_http_native: ^3.0.0-alpha.3 copied to clipboard
Fast native HTTP/1.1 server for Dart and the Dox framework. Rust (hyper) parses HTTP, your handlers stay in Dart. Implements the dart:io HttpServer API.
dox_http_native #
A fast HTTP/1.1 server for Dart. Rust (hyper) owns the sockets and parses HTTP. Your handlers stay in Dart.
It implements the dart:io HttpServer, HttpRequest and HttpResponse
API, so code written for dart:io works unchanged.
Dox uses it as its default server. You do not need to add it yourself when you use Dox.
import 'dart:io';
import 'package:dox_http_native/dox_http_native.dart';
void main() async {
NativeHttpServer server = await NativeHttpServer.bind(3000);
server.listen((HttpRequest req) {
req.response.write('Hello World');
req.response.close();
});
}
- No Rust needed: the build hook downloads a ready-built library (macOS arm64/x64, Linux x64/arm64, Windows x64).
- Use
dart run,dart testordart build cli.dart compile exedoes not run build hooks. - Each isolate can bind the same port (
SO_REUSEPORTon Linux, one shared socket on macOS). - Each isolate has its own
dox-httpthread.DOX_HTTP_THREAD=sharedputs them all on one thread (slower on 2 cores in our tests). 400for bad requests,431for headers over 16 KB,413for bodies overmaxBodySize.- Not yet: WebSocket upgrade (
detachSocket), streaming a response while it is written (the body is sent onclose).
More: Native server.