Skip to main content

land_scheme_handler

Function land_scheme_handler 

Source
pub fn land_scheme_handler(request: &Request<Vec<u8>>) -> Response<Vec<u8>>
Expand description

Handles land:// custom protocol requests

This function is called by Tauri when a webview makes a request to the land:// protocol. It routes the request to local HTTP services via the ServiceRegistry.

§Parameters

  • request: The incoming webview request with URI path and headers

§Returns

A Tauri response with:

  • Status code from local service (or error status)
  • Headers from local service plus CORS headers
  • Response body from local service (or error body)

§Implementation Details

  1. Parse the land:// URI to extract domain and path
  2. Look up the service in the ServiceRegistry
  3. Handle CORS preflight (OPTIONS) requests
  4. Check cache for static assets
  5. Forward the request to the local service
  6. Add CORS headers to the response
  7. Cache static assets for future requests

§Error Handling

  • 400: Invalid URI format
  • 404: Service not found in registry
  • 503: Service unavailable / request failed

§Example

tauri::Builder::default()
	.register_uri_scheme_protocol("land", |_app, request| land_scheme_handler(request))