v0.24.5
This commit is contained in:
commit
5e23e9af02
240 files changed
+99957
No files matched your search
@@ -0,0 +1,52 @@
|
||||
use axum::body::Body;
|
||||
use http::{Method, Request, Version};
|
||||
use rust_proxy::proxy::websocket::{h2_protocol, validate_h2};
|
||||
|
||||
fn extended_connect(protocol: &'static str) -> Request<Body> {
|
||||
let mut request = Request::builder()
|
||||
.method(Method::CONNECT)
|
||||
.version(Version::HTTP_2)
|
||||
.uri("https://example.test/socket")
|
||||
.header("sec-websocket-version", "13")
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
request
|
||||
.extensions_mut()
|
||||
.insert(hyper::ext::Protocol::from_static(protocol));
|
||||
request
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rfc8441_extended_connect_is_recognized() {
|
||||
let request = extended_connect("websocket");
|
||||
assert_eq!(h2_protocol(&request), Some("websocket"));
|
||||
let handshake = validate_h2(&request).expect("valid RFC 8441 bootstrap");
|
||||
assert!(handshake.h2());
|
||||
assert!(handshake.upstream_key().is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rfc8441_rejects_h1_upgrade_fields_and_other_protocols() {
|
||||
let mut request = extended_connect("websocket");
|
||||
request
|
||||
.headers_mut()
|
||||
.insert("upgrade", "websocket".parse().unwrap());
|
||||
assert!(validate_h2(&request).is_err());
|
||||
|
||||
let request = extended_connect("connect-udp");
|
||||
assert!(validate_h2(&request).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rfc8441_vhost_flag_deserializes_explicitly() {
|
||||
let value = serde_json::json!({
|
||||
"id": "ws-h2",
|
||||
"frontend": {"hosts": ["example.test"], "listener_ids": ["http"]},
|
||||
"backends": [{"id": "origin", "url": "http://127.0.0.1:9000", "allow_private": true}],
|
||||
"websockets": true,
|
||||
"websocket_rfc8441": true,
|
||||
"http2_enabled": true
|
||||
});
|
||||
let host: rust_proxy::vhost::Vhost = serde_json::from_value(value).unwrap();
|
||||
assert!(host.websockets && host.websocket_rfc8441 && host.http2_enabled);
|
||||
}
|
||||
Reference in new issue
Block a user