warp_subdomain

A simple subdomain parser middleware for Warp.

Usage

... warp route .and(warp_subdomain::with_subdomain)` ... route handler

Example

``` use std::collections::HashMap; use std::sync::Arc;

use warp::Filter;

use warpsubdomain::withsubdomain;

async fn query( query: HashMap, subdomain: Arc>, ) -> Result { // get last subdomain let subdomain0 = subdomain.get(0);

Ok(warp::reply::with_status(
    subdomain_0.unwrap().to_string(),
    warp::http::StatusCode::FOUND,
))

}

[tokio::main]

async fn main() { let route = warp::path!("home") .and(warp::get()) .and(warp::query::>()) .and(withsubdomain()) .andthen(query);

warp::serve(route).run(([127, 0, 0, 1], 3030)).await

}

```

If host eg. super-alloy.api.cilen.com.
This middleware will return Arc::Vec<String> = vec!["super-alloy", "api"]

This middleware also works for localhost that have port in host header. eg. api.localhost:3999

Note

This middlewares will return value with type Arc<Vec<String>>

Misc