mirror of
https://github.com/rwf2/Rocket.git
synced 2025-01-05 17:22:36 +00:00
03127f4dae
This commit adds the 'local::blocking' module and moves the existing asynchronous testing to 'local::asynchronous'. It also includes several changes to improve the local API, bringing it to parity (and beyond) with master. These changes are: * 'LocalRequest' implements 'Clone'. * 'LocalResponse' doesn't implement 'DerefMut<Target=Response>'. Instead, direct methods on the type, such as 'into_string()', can be used to read the 'Response'. * 'Response::body()' returns an '&ResponseBody' as opposed to '&mut ResponseBody', which is returned by a new 'Response::body_mut()'. * '&ResponseBody' implements 'known_size()` to retrieve a body's size, if it is known. Co-authored-by: Jeb Rosen <jeb@jebrosen.com>
35 lines
947 B
Rust
35 lines
947 B
Rust
#![feature(proc_macro_hygiene)]
|
|
|
|
#[macro_use] extern crate rocket;
|
|
|
|
use rocket::response::Redirect;
|
|
|
|
#[get("/google")]
|
|
fn google() -> Redirect {
|
|
Redirect::to("https://www.google.com")
|
|
}
|
|
|
|
#[get("/rocket")]
|
|
fn rocket() -> Redirect {
|
|
Redirect::to("https://rocket.rs:80")
|
|
}
|
|
|
|
mod test_absolute_uris_okay {
|
|
use super::*;
|
|
use rocket::local::asynchronous::Client;
|
|
|
|
#[rocket::async_test]
|
|
async fn redirect_works() {
|
|
let rocket = rocket::ignite().mount("/", routes![google, rocket]);
|
|
let client = Client::new(rocket).await.unwrap();
|
|
|
|
let response = client.get("/google").dispatch().await;
|
|
let location = response.headers().get_one("Location");
|
|
assert_eq!(location, Some("https://www.google.com"));
|
|
|
|
let response = client.get("/rocket").dispatch().await;
|
|
let location = response.headers().get_one("Location");
|
|
assert_eq!(location, Some("https://rocket.rs:80"));
|
|
}
|
|
}
|