mirror of https://github.com/rwf2/Rocket.git
36 lines
944 B
Rust
36 lines
944 B
Rust
#![feature(plugin, decl_macro, proc_macro_non_items)]
|
|
#![plugin(rocket_codegen)]
|
|
|
|
#[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::Client;
|
|
|
|
#[test]
|
|
fn redirect_works() {
|
|
let rocket = rocket::ignite().mount("/", routes![google, rocket]);
|
|
let client = Client::new(rocket).unwrap();
|
|
|
|
let response = client.get("/google").dispatch();
|
|
let location = response.headers().get_one("Location");
|
|
assert_eq!(location, Some("https://www.google.com"));
|
|
|
|
let response = client.get("/rocket").dispatch();
|
|
let location = response.headers().get_one("Location");
|
|
assert_eq!(location, Some("https://rocket.rs:80"));
|
|
}
|
|
}
|