Skip to main content

Module fetch

Module fetch 

Source
Expand description

Non-blocking / streaming HTTP fetch for Oxide guest modules.

The legacy api_fetch import (in crate::capabilities) blocks the guest until the entire response body has been downloaded. That prevents guests from rendering frames during large downloads and makes LLM-style token-streaming, chunked feeds, or progressive image loads impossible.

This module exposes a second fetch API that is fully async from the guest’s perspective. The shape mirrors crate::websocket:

  • api_fetch_begin dispatches a request and returns a handle immediately.
  • api_fetch_state / api_fetch_status report progress.
  • api_fetch_recv pulls the next body chunk from an in-memory queue.
  • api_fetch_abort cancels an in-flight request.
  • api_fetch_remove frees host-side resources once the guest is done.

A background tokio task per request drives reqwest’s bytes_stream(), pushing chunks into a VecDeque<Vec<u8>> drained by the guest.

Structs§

FetchState
All streaming-fetch state for a host. Lazily initialised on the first api_fetch_begin call.

Constants§

FETCH_ABORTED
Request was aborted by the guest.
FETCH_DONE
Body fully delivered and the queue may still contain trailing chunks.
FETCH_ERROR
Request failed. Use api_fetch_error to retrieve the message.
FETCH_PENDING
Request dispatched; waiting for response headers.
FETCH_STREAMING
Headers received; body chunks may be streaming in.

Functions§

register_fetch_functions
Register all api_fetch_* streaming host functions on the given linker.