pub enum HttpDownloadState {
Init {
url: Url,
},
Resolving {
dns: DnsResolveState,
host: String,
port: u16,
path: String,
query: Option<String>,
},
Connecting {
tcp: TcpConnState,
ip: Ipv4Addr,
port: u16,
host_header: String,
request_uri: String,
},
SendingRequest {
socket_handle: usize,
request: Vec<u8>,
sent: usize,
start_tsc: TscTimestamp,
},
ReceivingHeaders {
socket_handle: usize,
accumulator: HeaderAccumulator,
start_tsc: TscTimestamp,
},
ReceivingBody {
socket_handle: usize,
response_info: HttpResponseInfo,
received: usize,
start_tsc: TscTimestamp,
last_activity_tsc: TscTimestamp,
},
Done {
response_info: HttpResponseInfo,
total_bytes: usize,
},
Failed {
error: HttpError,
},
}Expand description
HTTP download state machine.
Orchestrates DNS resolution → TCP connection → HTTP request/response. Supports streaming for large downloads.
Variants§
Init
Initial state with target URL.
Resolving
Resolving hostname to IP address.
Fields
dns: DnsResolveStateDNS state machine
Connecting
Connecting to server.
Fields
tcp: TcpConnStateTCP state machine
SendingRequest
Sending HTTP request.
Fields
start_tsc: TscTimestampWhen send started
ReceivingHeaders
Receiving HTTP response headers.
Fields
accumulator: HeaderAccumulatorHeader accumulator
start_tsc: TscTimestampWhen receive started
ReceivingBody
Receiving HTTP response body.
Fields
response_info: HttpResponseInfoResponse info from headers
start_tsc: TscTimestampWhen body receive started
last_activity_tsc: TscTimestampLast activity time (for idle timeout)
Done
Download complete.
Fields
response_info: HttpResponseInfoResponse info
Failed
Download failed.
Implementations§
Source§impl HttpDownloadState
impl HttpDownloadState
Sourcepub fn start(&mut self, _now_tsc: u64)
pub fn start(&mut self, _now_tsc: u64)
Start the download.
Transitions from Init to Resolving (or Connecting if IP known).
Sourcepub fn step(
&mut self,
dns_result: Result<Option<Ipv4Addr>, ()>,
tcp_state: TcpSocketState,
recv_data: Option<&[u8]>,
_can_send: bool,
now_tsc: u64,
dns_timeout: u64,
tcp_timeout: u64,
http_send_timeout: u64,
http_recv_timeout: u64,
) -> StepResult
pub fn step( &mut self, dns_result: Result<Option<Ipv4Addr>, ()>, tcp_state: TcpSocketState, recv_data: Option<&[u8]>, _can_send: bool, now_tsc: u64, dns_timeout: u64, tcp_timeout: u64, http_send_timeout: u64, http_recv_timeout: u64, ) -> StepResult
Step the state machine.
§Arguments
dns_result: Result from smoltcp DNS query (if resolving)tcp_state: Current TCP socket state (if connected)recv_data: Data received from socket (if any)can_send: Whether socket can accept more datanow_tsc: Current TSC valuetimeouts: Timeout configuration (DNS, TCP, HTTP timeouts)
§Returns
Pending: Still in progressDone: Download complete, callresult()for infoTimeout: Operation timed outFailed: Operation failed, callerror()for details
§Callback
When recv_data contains body data during ReceivingBody state,
the caller should pass that data to the storage layer.
Sourcefn step_inner(
&self,
current: HttpDownloadState,
dns_result: Result<Option<Ipv4Addr>, ()>,
tcp_state: TcpSocketState,
recv_data: Option<&[u8]>,
_can_send: bool,
now_tsc: u64,
dns_timeout: u64,
tcp_timeout: u64,
http_send_timeout: u64,
http_recv_timeout: u64,
) -> (HttpDownloadState, StepResult)
fn step_inner( &self, current: HttpDownloadState, dns_result: Result<Option<Ipv4Addr>, ()>, tcp_state: TcpSocketState, recv_data: Option<&[u8]>, _can_send: bool, now_tsc: u64, dns_timeout: u64, tcp_timeout: u64, http_send_timeout: u64, http_recv_timeout: u64, ) -> (HttpDownloadState, StepResult)
Internal step implementation.
Sourcepub fn request_bytes(&self) -> Option<(&[u8], usize)>
pub fn request_bytes(&self) -> Option<(&[u8], usize)>
Get the request bytes to send (for SendingRequest state).
Sourcepub fn socket_handle(&self) -> Option<usize>
pub fn socket_handle(&self) -> Option<usize>
Get socket handle (if connected).
Sourcepub fn progress(&self) -> Option<HttpProgress>
pub fn progress(&self) -> Option<HttpProgress>
Get download progress.
Sourcepub fn response_info(&self) -> Option<&HttpResponseInfo>
pub fn response_info(&self) -> Option<&HttpResponseInfo>
Get response info (if headers received).
Sourcepub fn result(&self) -> Option<(&HttpResponseInfo, usize)>
pub fn result(&self) -> Option<(&HttpResponseInfo, usize)>
Get result (if complete).
Sourcepub fn is_terminal(&self) -> bool
pub fn is_terminal(&self) -> bool
Check if download is complete (success or failure).