Skip to content

Getting request body in from_request? #700

@raintears

Description

@raintears

I notice there are two guards: request guard and data guard. Request guard implements from_request and data guard implements from_data. But is there a way to get the request body in request guard?

I'm trying to do hmac calculation in the guard methods but I can't find a way to get the request body content. I can only get the headers.

This is what I was doing:

pub struct Hmac_str(pub String);

impl<'r, 'a> FromRequest<'r, 'a> for Hmac_str {
    type Error = ();

    fn from_request(request: &'r Request<'a>) -> request::Outcome<Hmac_str, ()> {
        ...
        // get headers and body to calculate hmac string
    }
}

I was also reading this guide https://api.rocket.rs/rocket/request/trait.FromRequest.html but I find that sending apikey can be prone to man-in-middle attack so was trying out hmac which I need to access the request content.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionA question (converts to discussion)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions