pub trait Contrib {
// Required methods
fn get_route_segments(&self) -> Option<Vec<&str>>;
fn is_preflight_request(&self) -> bool;
fn get_header_value_as_string(&self, header_name: &str) -> String;
}Expand description
Extensions for spin_sdk::http::Request
Required Methods§
Sourcefn get_route_segments(&self) -> Option<Vec<&str>>
fn get_route_segments(&self) -> Option<Vec<&str>>
returns route segments of the HTTP request.
If the request was invoked using the root URL, an empty vector is returned
§Example
use spin_sdk::http::RequestBuilder;
use spin_contrib_http::request::Contrib;
let fake_req = RequestBuilder::new(spin_sdk::http::Method::Get, "http://foo/bar")
.header("spin-path-info", "/foo/bar/baz")
.body(()).build();
let segments = fake_req.get_route_segments();
assert_eq!(segments.is_some(), true);
let segments = segments.unwrap();
assert_eq!(segments.len(), 3);
assert_eq!(segments[0], "foo");
assert_eq!(segments[1], "bar");
assert_eq!(segments[2], "baz");Sourcefn is_preflight_request(&self) -> bool
fn is_preflight_request(&self) -> bool
Determines if the request is a preflight request
Sourcefn get_header_value_as_string(&self, header_name: &str) -> String
fn get_header_value_as_string(&self, header_name: &str) -> String
Returns a header value as String. If header is not present or value is empty, an empty string is returned