morpheus_network::state::http

Enum HttpDownloadState

Source
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.

Fields

§url: Url
§

Resolving

Resolving hostname to IP address.

Fields

§dns: DnsResolveState

DNS state machine

§host: String

Target host

§port: u16

Target port

§path: String

Request path

§query: Option<String>

Query string (if any)

§

Connecting

Connecting to server.

Fields

§tcp: TcpConnState

TCP state machine

§ip: Ipv4Addr

Resolved IP

§port: u16

Target port

§host_header: String

Host header value

§request_uri: String

Request path + query

§

SendingRequest

Sending HTTP request.

Fields

§socket_handle: usize

Socket handle

§request: Vec<u8>

Serialized HTTP request

§sent: usize

Bytes sent so far

§start_tsc: TscTimestamp

When send started

§

ReceivingHeaders

Receiving HTTP response headers.

Fields

§socket_handle: usize

Socket handle

§accumulator: HeaderAccumulator

Header accumulator

§start_tsc: TscTimestamp

When receive started

§

ReceivingBody

Receiving HTTP response body.

Fields

§socket_handle: usize

Socket handle

§response_info: HttpResponseInfo

Response info from headers

§received: usize

Bytes received so far

§start_tsc: TscTimestamp

When body receive started

§last_activity_tsc: TscTimestamp

Last activity time (for idle timeout)

§

Done

Download complete.

Fields

§response_info: HttpResponseInfo

Response info

§total_bytes: usize

Total bytes received (body only)

§

Failed

Download failed.

Fields

§error: HttpError

Error details

Implementations§

Source§

impl HttpDownloadState

Source

pub fn new(url: Url) -> Result<Self, HttpError>

Create new HTTP download state machine.

Source

pub fn start(&mut self, _now_tsc: u64)

Start the download.

Transitions from Init to Resolving (or Connecting if IP known).

Source

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 data
  • now_tsc: Current TSC value
  • timeouts: Timeout configuration (DNS, TCP, HTTP timeouts)
§Returns
  • Pending: Still in progress
  • Done: Download complete, call result() for info
  • Timeout: Operation timed out
  • Failed: Operation failed, call error() for details
§Callback

When recv_data contains body data during ReceivingBody state, the caller should pass that data to the storage layer.

Source

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.

Source

fn build_request(host: &str, request_uri: &str) -> Vec<u8>

Build HTTP GET request.

Source

pub fn request_bytes(&self) -> Option<(&[u8], usize)>

Get the request bytes to send (for SendingRequest state).

Source

pub fn mark_sent(&mut self, additional: usize)

Update bytes sent (for SendingRequest state).

Source

pub fn socket_handle(&self) -> Option<usize>

Get socket handle (if connected).

Source

pub fn progress(&self) -> Option<HttpProgress>

Get download progress.

Source

pub fn response_info(&self) -> Option<&HttpResponseInfo>

Get response info (if headers received).

Source

pub fn result(&self) -> Option<(&HttpResponseInfo, usize)>

Get result (if complete).

Source

pub fn error(&self) -> Option<&HttpError>

Get error (if failed).

Source

pub fn is_terminal(&self) -> bool

Check if download is complete (success or failure).

Source

pub fn is_active(&self) -> bool

Check if download is in progress.

Trait Implementations§

Source§

impl Debug for HttpDownloadState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HttpDownloadState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.