Update to Rocket 0.5

Though Rocket 0.5 still only a release candidate, Rocket 0.4 severely
outdated, and depends on a bunch of crates with active security
advisories. Rocket 0.5 updates its dependencies to fixes versions.

Also Rocket 0.4 needs a nightly Rust, which caused multiple problems.
This commit is contained in:
René Kijewski 2022-06-16 07:44:06 +02:00 committed by Dirkjan Ochtman
parent d4c13f5b43
commit 5cdffd6e0e
5 changed files with 22 additions and 17 deletions

View File

@ -81,7 +81,7 @@ jobs:
- uses: actions-rs/toolchain@v1 - uses: actions-rs/toolchain@v1
with: with:
profile: minimal profile: minimal
toolchain: nightly toolchain: stable
override: true override: true
components: clippy components: clippy
- run: cargo test --package askama_rocket --all-targets - run: cargo test --package askama_rocket --all-targets

View File

@ -506,7 +506,7 @@ impl<'a> Generator<'a> {
let param = syn::GenericParam::Lifetime(syn::LifetimeDef::new(lifetime)); let param = syn::GenericParam::Lifetime(syn::LifetimeDef::new(lifetime));
self.write_header( self.write_header(
buf, buf,
"::askama_rocket::Responder<'askama>", "::askama_rocket::Responder<'askama, 'askama>",
Some(vec![param]), Some(vec![param]),
)?; )?;

View File

@ -14,7 +14,10 @@ edition = "2018"
[dependencies] [dependencies]
askama = { version = "0.11.2", path = "../askama", default-features = false, features = ["with-rocket", "mime", "mime_guess"] } askama = { version = "0.11.2", path = "../askama", default-features = false, features = ["with-rocket", "mime", "mime_guess"] }
rocket = { version = "0.4", default-features = false } rocket = { version = "0.5.0-rc.2", default-features = false }
[dev-dependencies]
futures-lite = "1.12.0"
[features] [features]
default = ["askama/default"] default = ["askama/default"]

View File

@ -14,6 +14,6 @@ pub fn respond<T: Template>(t: &T, _ext: &str) -> Result<'static> {
let rsp = t.render().map_err(|_| Status::InternalServerError)?; let rsp = t.render().map_err(|_| Status::InternalServerError)?;
Response::build() Response::build()
.header(Header::new("content-type", T::MIME_TYPE)) .header(Header::new("content-type", T::MIME_TYPE))
.sized_body(Cursor::new(rsp)) .sized_body(rsp.len(), Cursor::new(rsp))
.ok() .ok()
} }

View File

@ -1,12 +1,8 @@
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use]
extern crate rocket;
use askama::Template; use askama::Template;
use futures_lite::future::block_on;
use rocket::http::{ContentType, Status}; use rocket::http::{ContentType, Status};
use rocket::local::Client; use rocket::local::asynchronous::Client;
#[derive(Template)] #[derive(Template)]
#[template(path = "hello.html")] #[template(path = "hello.html")]
@ -14,17 +10,23 @@ struct HelloTemplate<'a> {
name: &'a str, name: &'a str,
} }
#[get("/")] #[rocket::get("/")]
fn hello() -> HelloTemplate<'static> { fn hello() -> HelloTemplate<'static> {
HelloTemplate { name: "world" } HelloTemplate { name: "world" }
} }
#[test] #[test]
fn test_rocket() { fn test_rocket() {
let rocket = rocket::ignite().mount("/", routes![hello]); block_on(async {
let client = Client::new(rocket).unwrap(); let rocket = rocket::build()
let mut rsp = client.get("/").dispatch(); .mount("/", rocket::routes![hello])
assert_eq!(rsp.status(), Status::Ok); .ignite()
assert_eq!(rsp.content_type(), Some(ContentType::HTML)); .await
assert_eq!(rsp.body_string().unwrap(), "Hello, world!"); .unwrap();
let client = Client::untracked(rocket).await.unwrap();
let rsp = client.get("/").dispatch().await;
assert_eq!(rsp.status(), Status::Ok);
assert_eq!(rsp.content_type(), Some(ContentType::HTML));
assert_eq!(rsp.into_string().await.as_deref(), Some("Hello, world!"));
});
} }