Repository: seanmonstar/warp (language: rust)

Issue:
panic on 'server URIs should always have path_and_query'
Hi,

I got the following panic in my application
```
thread 'main' panicked at 'server URIs should always have path_and_query', src/libcore/option.rs:1188:5
```
My main function where I set up my filters for warp looks like (the https feature was enabled):
```
#[tokio::main]
async fn main() {
    let config = get_config();
    let req_cache = create_cache();

    let dist = warp::filters::query::query::<Request>()
        .map(move |req| (config, req_cache, req))
        .and_then(spawn_worker)
        .or(warp::fs::dir(&config.dist));

    if cfg!(feature = "https") {
        warp::serve(dist)
            .tls()
            .cert_path(config.tls_cert.as_ref().unwrap())
            .key_path(config.tls_key.as_ref().unwrap())
            .run(config.address)
            .await
    } else {
        warp::serve(dist).run(config.address).await
    }
}
```
Unfortunately as you can see I didn't have any logging set up for the requests, so I don't know what request caused it to crash, nor did I have RUST_BACKTRACE set (double oops), so I apologize if this issue isn't very helpful.


Discussion / hints:

Fix patch:
diff --git a/src/filters/path.rs b/src/filters/path.rs
index bfaa33d82..a09526d65 100644
--- a/src/filters/path.rs
+++ b/src/filters/path.rs
@@ -465,8 +465,8 @@ fn path_and_query(route: &Route) -> PathAndQuery {
     route
         .uri()
         .path_and_query()
-        .expect("server URIs should always have path_and_query")
-        .clone()
+        .cloned()
+        .unwrap_or_else(|| PathAndQuery::from_static(""))
 }
 
 /// Convenient way to chain multiple path filters together.


Test patch:
diff --git a/tests/path.rs b/tests/path.rs
index 5390e51ef..14e1a10da 100644
--- a/tests/path.rs
+++ b/tests/path.rs
@@ -303,6 +303,14 @@ async fn full_path() {
     // does not modify matching
     let m = full_path.and(foo).and(bar);
     assert!(warp::test::request().path("/foo/bar").matches(&m).await);
+
+    // doesn't panic on authority-form
+    let ex = warp::test::request()
+        .path("localhost:1234")
+        .filter(&full_path)
+        .await
+        .unwrap();
+    assert_eq!(ex.as_str(), "/");
 }
 
 #[tokio::test]