forked from rwf2/Rocket
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix response part of rwf2#1067 by importing typed headers from 'heade…
…rs' crate
- Loading branch information
Showing
4 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#[macro_use] | ||
extern crate rocket; | ||
|
||
use std::time::{Duration, SystemTime}; | ||
use rocket::http::Expires; | ||
|
||
#[derive(Responder)] | ||
struct MyResponse { | ||
body: String, | ||
expires: Expires, | ||
} | ||
|
||
#[get("/")] | ||
fn index() -> MyResponse { | ||
let some_future_time = | ||
SystemTime::UNIX_EPOCH.checked_add(Duration::from_secs(60 * 60 * 24 * 365 * 100)).unwrap(); | ||
|
||
MyResponse { | ||
body: "Hello, world!".into(), | ||
expires: Expires::from(some_future_time) | ||
} | ||
} | ||
|
||
#[test] | ||
fn typed_header() { | ||
let rocket = rocket::build().mount("/", routes![index]); | ||
let client = rocket::local::blocking::Client::debug(rocket).unwrap(); | ||
let response = client.get("/").dispatch(); | ||
assert_eq!(response.headers().get_one("Expires").unwrap(), "Sat, 07 Dec 2069 00:00:00 GMT"); | ||
} |