Move to async rocket

This commit is contained in:
jordan@doyle.la 2020-04-13 01:27:39 +01:00
parent b095d2464c
commit 296cd50b7b
No known key found for this signature in database
GPG key ID: 1EA6BAE6F66DC49A
6 changed files with 597 additions and 155 deletions

View file

@ -3,6 +3,8 @@ use std::ops::Deref;
use rocket::request::{FromRequest, Outcome};
use rocket::Request;
use async_trait::async_trait;
/// Holds a value that determines whether or not this request wanted a plaintext response.
///
/// We assume anything with the text/plain Accept or Content-Type headers want plaintext,
@ -17,10 +19,11 @@ impl Deref for IsPlaintextRequest {
}
}
#[async_trait]
impl<'a, 'r> FromRequest<'a, 'r> for IsPlaintextRequest {
type Error = ();
fn from_request(request: &'a Request<'r>) -> Outcome<IsPlaintextRequest, ()> {
async fn from_request(request: &'a Request<'r>) -> Outcome<IsPlaintextRequest, ()> {
if let Some(format) = request.format() {
if format.is_plain() {
return Outcome::Success(IsPlaintextRequest(true));
@ -54,10 +57,11 @@ impl<'a> Deref for HostHeader<'a> {
}
}
#[async_trait]
impl<'a, 'r> FromRequest<'a, 'r> for HostHeader<'a> {
type Error = ();
fn from_request(request: &'a Request<'r>) -> Outcome<HostHeader<'a>, ()> {
async fn from_request(request: &'a Request<'r>) -> Outcome<HostHeader<'a>, ()> {
Outcome::Success(HostHeader(request.headers().get_one("Host")))
}
}