MCPcopy Create free account
hub / github.com/ElementsProject/lightning / create_cors_layer

Function create_cors_layer

plugins/rest-plugin/src/options.rs:113–140  ·  view source on GitHub ↗
(allowed_origins: &[String])

Source from the content-addressed store, hash-verified

111}
112
113fn create_cors_layer(allowed_origins: &[String]) -> Result<CorsLayer, anyhow::Error> {
114 if allowed_origins.is_empty() {
115 return Err(anyhow!("`clnrest-cors-origins` must not be empty!"));
116 }
117 if allowed_origins.first().unwrap() == "*" {
118 Ok(CorsLayer::new()
119 .allow_origin(Any)
120 .allow_methods(Any)
121 .allow_headers(Any))
122 } else {
123 let origins = allowed_origins
124 .iter()
125 .map(|header_val| {
126 HeaderValue::from_str(header_val).map_err(|err| {
127 anyhow!(
128 "Could not parse CORS header value `{}`: {}",
129 header_val,
130 err
131 )
132 })
133 })
134 .collect::<Result<Vec<HeaderValue>, anyhow::Error>>()?;
135 Ok(CorsLayer::new()
136 .allow_origin(origins)
137 .allow_methods(Any)
138 .allow_headers(Any))
139 }
140}

Callers 1

parse_optionsFunction · 0.85

Calls 2

mapMethod · 0.80
unwrapMethod · 0.45

Tested by

no test coverage detected