use core::ptr::NonNull;
use bun_core::strings;
use crate::HTTPClient;
use crate::NewHTTPContext;
use crate::ssl_config::SSLConfig;
#[derive(Default)]
pub struct PendingConnect {
pub hostname: Box<[u8]>,
pub port: u16,
pub ssl_config: Option<NonNull<SSLConfig>>,
pub reject_unauthorized: bool,
pub host_header_hash: u64,
pub waiters: Vec<NonNull<HTTPClient<'static>>>,
}
impl PendingConnect {
pub fn new(init: Self) -> Box<Self> {
Box::new(init)
}
#[inline]
pub fn waiter_mut<'a>(p: NonNull<HTTPClient<'static>>) -> &'a mut HTTPClient<'static> {
HTTPClient::from_erased_backref(p)
}
pub fn matches(
&self,
hostname: &[u8],
port: u16,
ssl_config: Option<NonNull<SSLConfig>>,
host_header_hash: u64,
) -> bool {
self.port == port
&& self.ssl_config == ssl_config
&& self.host_header_hash == host_header_hash
&& strings::eql_long(&self.hostname, hostname, true)
}
pub fn unregister_from(this: *const Self, ctx: &mut NewHTTPContext<true>) -> Option<Box<Self>> {
let list = &mut ctx.pending_h2_connects;
list.iter()
.position(|p| core::ptr::eq(&raw const **p, this))
.map(|i| list.swap_remove(i))
}
}