Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add map_request and friends #1408

Merged
merged 7 commits into from Sep 25, 2022
Merged

Add map_request and friends #1408

merged 7 commits into from Sep 25, 2022

Conversation

davidpdrsn
Copy link
Member

@davidpdrsn davidpdrsn commented Sep 23, 2022

Fixes #1394 (comment)

I'll do map_response in a separate PR.

@davidpdrsn davidpdrsn marked this pull request as ready for review September 25, 2022 10:45
axum/src/middleware/map_request.rs Outdated Show resolved Hide resolved
axum/src/middleware/map_request.rs Outdated Show resolved Hide resolved
Comment on lines +67 to +76
/// async fn auth<B>(request: Request<B>) -> Result<Request<B>, StatusCode> {
/// let auth_header = request.headers()
/// .get(http::header::AUTHORIZATION)
/// .and_then(|header| header.to_str().ok());
///
/// match auth_header {
/// Some(auth_header) if token_is_valid(auth_header) => Ok(request),
/// _ => Err(StatusCode::UNAUTHORIZED),
/// }
/// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a new "simplest way to write an auth middleware", which feels like one of our most frequently asked questions 🥳

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda wanna nuke tower-http's auth middleware. They're so much more complicated than just doing this.

axum/src/middleware/map_request.rs Show resolved Hide resolved
axum/src/middleware/map_request.rs Show resolved Hide resolved
axum/src/middleware/map_request.rs Outdated Show resolved Hide resolved
axum/src/middleware/map_request.rs Outdated Show resolved Hide resolved
};
}

impl_service!([], T1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, should all_the_tuples! just be updated to this pattern instead of the array-free one? Idk whether I've said this elsewhere but my idea to get rid of the array syntax in these macros turned out to not really work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think it should. Its only HandleError that uses the old version https://github.com/tokio-rs/axum/blob/main/axum/src/error_handling/mod.rs#L207. I'll do that separately.

davidpdrsn and others added 2 commits September 25, 2022 13:16
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
axum/src/middleware/from_fn.rs Outdated Show resolved Hide resolved
axum/src/middleware/from_fn.rs Outdated Show resolved Hide resolved
axum/src/middleware/map_request.rs Outdated Show resolved Hide resolved
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
@davidpdrsn davidpdrsn enabled auto-merge (squash) September 25, 2022 11:37
@davidpdrsn davidpdrsn merged commit 2077d50 into main Sep 25, 2022
@davidpdrsn davidpdrsn deleted the map-request branch September 25, 2022 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

middleware::map_request[_with_state[_arc]] and map_response[_with_state[_arc]]
3 participants