Dever v0.0.2

This commit is contained in:
Codex committed 2026-11-27 06:03:56 +00:00
commit e6e175ebcf
816 files changed
+120349

No files matched your search

+69
View File
@@ -0,0 +1,69 @@
use dever_runtime::{Bytes, http, net, task};
use std::sync::Arc;
let settings = Arc::new(SettingValues { f0: "shared".into() });
for http2 in [false, true] {
for mode in 0..9 {
let settings = settings.clone();
task::run(true, 32, async |scope| {
let listener = net::listen("127.0.0.1", 0, scope).await.unwrap();
let port = listener.port().unwrap();
let active = listener.clone();
let server = scope.spawn(move |child| async move {
let mut limits = @defaultLimits@();
if http2 { limits.f4 = Some(@defaultHttp2Limits@()); }
match mode {
0 => @start@(&child, &active, &limits).await,
1 => @startAsync@(&child, &active, &limits).await,
2 => @startTasks@(&child, &active, &limits).await,
3 => @startConfig@(&child, &settings, &active, &limits).await,
4 => @startFailure@(&child, &active, &limits).await,
5 => @startFault@(&child, &active, &limits).await,
6 => @startLive@(&child, &active, &limits).await,
7 => @startEvents@(&child, &active, &limits).await,
_ => @startComplete@(&child, &active, &limits).await,
}
}).unwrap();
let limits = http::Limits { header_bytes: 8192, body_bytes: 1048576, timeout_ms: 1000, connections: 32, http2: http2.then_some(http::Http2Limits { streams: 16, stream_window_bytes: 65535, connection_window_bytes: 262144 }) };
for target in ["/fail", "/echo?q=one%20two"] {
let body = if mode == 5 { if target == "/fail" { b"9223372036854775807".as_slice() } else { b"199".as_slice() } } else { b"native".as_slice() };
let response = http::send("127.0.0.1", port, http::Request { method: "POST".into(), target: target.into(), headers: vec![http::Header { name: "host".into(), value: Bytes::from_static(b"localhost") }], body: Bytes::from_static(body) }, &limits).await.unwrap();
let status = if (mode == 4 || mode == 5) && target == "/fail" { 500 } else if mode == 3 { 201 } else { 200 };
assert_eq!(response.status, status);
assert_eq!(response.body.as_ref(), if status == 500 { b"".as_slice() } else if mode == 7 { b"event: message
data: native
".as_slice() } else { body });
if mode == 3 {
for (name, value) in [("x-prefix", "shared"), ("x-method", "POST"), ("x-target", target)] {
assert!(response.headers.iter().any(|h| h.name == name && h.value == value.as_bytes()));
}
}
}
listener.close().unwrap();
server.await.unwrap().unwrap();
Ok::<_, ()>(())
}).unwrap().unwrap();
}
}
task::run(true, 16, async |scope| {
let listener = net::listen("127.0.0.1", 0, scope).await.unwrap();
let port = listener.port().unwrap();
let active = listener.clone();
let fixtures = std::path::Path::new(@tls_fixtures@);
let tls = dever_runtime::tls::server(&std::fs::read(fixtures.join("server.pem")).unwrap(), &std::fs::read(fixtures.join("server-key.pem")).unwrap()).unwrap();
let server = scope.spawn(move |child| async move { @startTls@(&child, &active, &@defaultLimits@(), &tls).await }).unwrap();
let root = fixtures.join("root.pem");
let response = scope.parallel(move || std::process::Command::new("python3").args(["-c", r#"
import ssl, http.client, sys
c = http.client.HTTPSConnection('localhost', int(sys.argv[1]), timeout=3, context=ssl.create_default_context(cafile=sys.argv[2]))
c.request('POST', '/tls', b'certificate verified')
r = c.getresponse()
assert r.status == 200
assert r.read() == b'certificate verified'
c.close()
"#, &port.to_string(), root.to_str().unwrap()]).output().unwrap()).await.unwrap();
assert!(response.status.success(), "{}", String::from_utf8_lossy(&response.stderr));
listener.close().unwrap();
server.await.unwrap().unwrap();
Ok::<_, ()>(())
}).unwrap().unwrap();