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

Axum HTTP tracker: extract Axum extractor for URL path auth key param #208

Conversation

josecelano
Copy link
Member

@josecelano josecelano commented Mar 1, 2023

Axum extractor to extract the key path param from the URLs:

Router::new()
    // Announce request
    .route("/announce", get(announce::handle_without_key).with_state(tracker.clone()))
    .route("/announce/:key", get(announce::handle_with_key).with_state(tracker.clone()))
    // Scrape request
    .route("/scrape", get(scrape::handle_without_key).with_state(tracker.clone()))
    .route("/scrape/:key", get(scrape::handle_with_key).with_state(tracker.clone()))
    // Add extension to get the client IP from the connection info
    .layer(SecureClientIpSource::ConnectInfo.into_extension())

It extracts the :key param. I'm using an extractor because we have a custom error response, and the handlers are much cleaner this way and we remove the duplicate code.

@josecelano josecelano changed the title Axum HTTP tracker: extract Axum extractor for URL path auth key param Axum HTTP tracker: extract Axum extractor for URL path auth key param Mar 1, 2023
@josecelano josecelano force-pushed the auxm-http-tracker-extract-key-id-extractor branch from a2d58c3 to 20436be Compare March 1, 2023 18:15
@josecelano josecelano force-pushed the auxm-http-tracker-extract-key-id-extractor branch from 20436be to a9e3a33 Compare March 1, 2023 18:33
@josecelano josecelano merged commit f3892cf into torrust:develop Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

1 participant