Comments (4)
I understand the use case, and would like to support it. The path
filter could be changed to allow passing a String
or something... but that would then prevent it from being impl Filter + Copy
.
As a stopgap, you can probably achieve what you want by making using of warp::path::param::<String>()
. You could then create dynamic filters like this:
let arg_path = clap.arg_something();
let clapped_path = warp::path::param()
.and_then(move |param: String| {
if param == arg_path {
Ok(())
} else {
Err(warp::reject::not_found())
}
});
from warp.
Another workaround: create a &'static str
at runtime with Box::leak(string.into_boxed_str())
.
It will leak the string's memory, but if the server runs until process termination that's not a big deal.
from warp.
Thanks for the help here, I've landed on this for the time being:
let telemetry_path = matches
.value_of("WEB_TELEMETRY_PATH")
.unwrap();
let telemetry_path = telemetry_path.to_owned();
let telemetry = warp::get2()
.and(warp::path::param::<String>())
.and_then(move |param: String| {
let mut get_path = "/".to_owned();
get_path.push_str(¶m);
if get_path == telemetry_path {
Ok(())
}
else {
Err(warp::reject::not_found())
}
});
let telemetry = telemetry.and_then(metrics);
let routes = telemetry;
let server = warp::serve(routes);
This is working fine and I learned a little more about move
in the process. Thanks again.
from warp.
I ran into a related issue (working with warp
on master which now supports async
/await
).
I'd like to be able to mount my app under an arbitrary path (eg "/foo/bar/wibble") so that it can happily be configured to coexist with other apps running (for example if I was to deploy it to k8s).
Using the Box::leak
trick gets me as far as being able to configure a single path piece (eg "/foo") to mount the app underneath, but since slashes aren't allowed I can't supply a full path to mount the app underneath.
I couldn't get the custom-filter approach to work at all, but it would have suffered from the same issue of only matching against a single piece of the path anyway.
It would be nice to be able to use String
s for paths in general, and also for slashes to work (perhaps using a new filter like full_path or somesuch? I'm not fully sure why they don't work already).
from warp.
Related Issues (20)
- Feature request: Fallible extractor filter
- Clarify API docs around multipart forms HOT 2
- Feature request: More customization points in tracing HOT 2
- EC Private key support HOT 1
- Make `Option<F>` a filter when F is a filter
- Feature request: `warp::make_service()` or `warp::service_with_addr()`
- CVE-2023-43669/GHSA-9mcr-873m-xcxp: tungstenite <= 0.20.0 DoS vulnerability HOT 1
- [feature request] [low prio] Non-Metal fallback option HOT 2
- SSE gives up on Streams that return Pending HOT 3
- Server::run should return ! (never type)
- Default OS / self signed certificate without create it HOT 1
- websocket disconnect (code: 1006, reason: "") HOT 2
- Add `rust-version` into `Cargo.toml` HOT 1
- Error `connection closed before message completed` after 60s HOT 2
- Websocket connection closes immediately, but not with firefox HOT 4
- Navigation between panes using vim commands HOT 1
- examples/tls/cert.pem has expired
- Upgrade to hyper v1 HOT 4
- key contains no private key while using ecc key HOT 1
- integrate with monoio
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from warp.