How to extract custom Header #1437
-
Hello people, thanks for this awesome framework. I've been struggling to extract a custom header. I'm trying to parse a git webhook with header #[derive(Deserialize, Debug, Clone)]
enum EventKey {
RepoPush,
}
impl FromStr for EventKey {
type Err = AppError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"repo:push" => Ok(Self::RepoPush),
_ => Err(AppError::InvalidHeader),
}
}
}
async fn webhook_handler(event_type: TypedHeader<EventKey>) -> Response {
println!("{event_type:?}");
return (StatusCode::OK, String::from("Ok")).into_response();
} The error I get:
I'm now trying to implement the Thanks in advance!! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Don't bother with |
Beta Was this translation helpful? Give feedback.
Don't bother with
TypedHeader
for something like this. Either write your ownFromRequest
implementation or extractHeaderMap
directly.