pub struct NativeHttpClient<D: NetworkDevice> {
iface: NetInterface<D>,
config: NativeClientConfig,
socket: Option<SocketHandle>,
get_time_ms: fn() -> u64,
}Expand description
Native bare-metal HTTP client.
Generic over NetworkDevice so it works with any driver:
- VirtIO (QEMU, KVM)
- Intel NICs (future)
- Realtek NICs (future)
- etc.
Fields§
§iface: NetInterface<D>Network interface with TCP/IP stack.
config: NativeClientConfigClient configuration.
socket: Option<SocketHandle>Current TCP socket handle (if connected).
get_time_ms: fn() -> u64Function to get current time in milliseconds. Must be provided by the caller (platform-specific).
Implementations§
Source§impl<D: NetworkDevice> NativeHttpClient<D>
impl<D: NetworkDevice> NativeHttpClient<D>
Sourcepub fn new(device: D, net_config: NetConfig, get_time_ms: fn() -> u64) -> Self
pub fn new(device: D, net_config: NetConfig, get_time_ms: fn() -> u64) -> Self
Create a new native HTTP client.
§Arguments
device- Network device to usenet_config- IP configuration (DHCP or static)get_time_ms- Function returning current time in milliseconds
Sourcepub fn with_config(
device: D,
net_config: NetConfig,
client_config: NativeClientConfig,
get_time_ms: fn() -> u64,
) -> Self
pub fn with_config( device: D, net_config: NetConfig, client_config: NativeClientConfig, get_time_ms: fn() -> u64, ) -> Self
Create with custom configuration.
Sourcepub fn is_network_ready(&self) -> bool
pub fn is_network_ready(&self) -> bool
Check if network is ready (has IP address).
Sourcepub fn ip_address(&self) -> Option<Ipv4Addr>
pub fn ip_address(&self) -> Option<Ipv4Addr>
Get current IP address.
Sourcepub fn wait_for_network(&mut self, timeout_ms: u64) -> Result<()>
pub fn wait_for_network(&mut self, timeout_ms: u64) -> Result<()>
Wait for network to be ready (DHCP complete or static configured).
Sourcepub fn resolve_host(&mut self, host: &str) -> Result<Ipv4Addr>
pub fn resolve_host(&mut self, host: &str) -> Result<Ipv4Addr>
Resolve hostname to IP address using DNS or hardcoded fallbacks.
Sourcefn try_dns_query(&mut self, host: &str) -> Result<Ipv4Addr>
fn try_dns_query(&mut self, host: &str) -> Result<Ipv4Addr>
Attempt DNS resolution via UDP query.
Sourcefn lookup_hardcoded_dns(&self, host: &str) -> Result<Ipv4Addr>
fn lookup_hardcoded_dns(&self, host: &str) -> Result<Ipv4Addr>
Lookup host in hardcoded DNS table.
Sourcefn close_existing_socket(&mut self)
fn close_existing_socket(&mut self)
Close any existing socket.
Sourcefn create_tcp_socket(&mut self) -> Result<SocketHandle>
fn create_tcp_socket(&mut self) -> Result<SocketHandle>
Create a new TCP socket.
Sourcefn initiate_connection(
&mut self,
handle: SocketHandle,
ip: Ipv4Addr,
port: u16,
) -> Result<()>
fn initiate_connection( &mut self, handle: SocketHandle, ip: Ipv4Addr, port: u16, ) -> Result<()>
Initiate TCP connection.
Sourcefn wait_for_connection(&mut self, handle: SocketHandle) -> Result<()>
fn wait_for_connection(&mut self, handle: SocketHandle) -> Result<()>
Wait for TCP connection to complete.
Sourcefn send_all(&mut self, data: &[u8]) -> Result<()>
fn send_all(&mut self, data: &[u8]) -> Result<()>
Send all data and wait for transmission to complete.
Sourcefn read_headers(&mut self) -> Result<Vec<u8>>
fn read_headers(&mut self) -> Result<Vec<u8>>
Read HTTP headers until \r\n\r\n found.
Sourcefn read_full_response(&mut self) -> Result<Vec<u8>>
fn read_full_response(&mut self) -> Result<Vec<u8>>
Read full HTTP response (headers + body).
Sourcefn read_remaining_body(
&mut self,
response_data: &mut Vec<u8>,
body_start: usize,
content_length: Option<usize>,
) -> Result<()>
fn read_remaining_body( &mut self, response_data: &mut Vec<u8>, body_start: usize, content_length: Option<usize>, ) -> Result<()>
Read remaining body data based on Content-Length.
Sourcefn stream_response_body<F>(
&mut self,
initial_body: &[u8],
content_length: Option<usize>,
callback: &mut F,
) -> Result<usize>
fn stream_response_body<F>( &mut self, initial_body: &[u8], content_length: Option<usize>, callback: &mut F, ) -> Result<usize>
Stream response body to callback.
Sourcefn do_request(&mut self, request: &Request) -> Result<Response>
fn do_request(&mut self, request: &Request) -> Result<Response>
Execute a basic HTTP request and return full response.
Sourcefn do_request_with_redirects(&mut self, request: Request) -> Result<Response>
fn do_request_with_redirects(&mut self, request: Request) -> Result<Response>
Execute request with automatic redirect following.
Sourcefn build_redirect_request(
&self,
original: &Request,
location: &str,
) -> Result<Request>
fn build_redirect_request( &self, original: &Request, location: &str, ) -> Result<Request>
Build a new request for a redirect location.
Sourcepub fn get(&mut self, url: &str) -> Result<Response>
pub fn get(&mut self, url: &str) -> Result<Response>
Simple GET request returning full response.
Sourcepub fn get_streaming<F>(&mut self, url: &str, callback: F) -> Result<usize>
pub fn get_streaming<F>(&mut self, url: &str, callback: F) -> Result<usize>
GET request with streaming callback for large downloads.
Sourcefn execute_streaming_request<F>(
&mut self,
url: &Url,
callback: &mut F,
) -> Result<usize>
fn execute_streaming_request<F>( &mut self, url: &Url, callback: &mut F, ) -> Result<usize>
Execute a streaming HTTP request.
Sourcefn stream_response<F>(&mut self, callback: &mut F) -> Result<usize>
fn stream_response<F>(&mut self, callback: &mut F) -> Result<usize>
Stream the HTTP response to the callback.
Sourcepub fn interface(&self) -> &NetInterface<D>
pub fn interface(&self) -> &NetInterface<D>
Get reference to the network interface.
Sourcepub fn interface_mut(&mut self) -> &mut NetInterface<D>
pub fn interface_mut(&mut self) -> &mut NetInterface<D>
Get mutable reference to the network interface.