{"id":18447532,"url":"https://github.com/mustakimali/actix-middleware-macro","last_synced_at":"2025-07-28T12:03:00.211Z","repository":{"id":224993911,"uuid":"764787821","full_name":"mustakimali/actix-middleware-macro","owner":"mustakimali","description":"A macro to generate actix-web middleware. Useful for the times when you can't be bothered to figure it out yourself for the 100th times.","archived":false,"fork":false,"pushed_at":"2024-02-28T18:22:24.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T17:15:24.300Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mustakimali.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-28T17:57:46.000Z","updated_at":"2024-02-28T18:24:35.000Z","dependencies_parsed_at":"2024-02-28T19:49:22.968Z","dependency_job_id":null,"html_url":"https://github.com/mustakimali/actix-middleware-macro","commit_stats":null,"previous_names":["mustakimali/actix-middleware-macro"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mustakimali/actix-middleware-macro","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustakimali%2Factix-middleware-macro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustakimali%2Factix-middleware-macro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustakimali%2Factix-middleware-macro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustakimali%2Factix-middleware-macro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mustakimali","download_url":"https://codeload.github.com/mustakimali/actix-middleware-macro/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustakimali%2Factix-middleware-macro/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263182184,"owners_count":23426633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T07:13:35.575Z","updated_at":"2025-07-02T17:07:24.073Z","avatar_url":"https://github.com/mustakimali.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# actix-middleware-macro\n\n[![Build](https://github.com/mustakimali/actix-middleware-macro/actions/workflows/rust.yml/badge.svg)](https://github.com/mustakimali/actix-middleware-macro/actions/workflows/rust.yml)\n[![Latest Version](https://img.shields.io/crates/v/actix-middleware-macro.svg)](https://crates.io/crates/actix-middleware-macro)\n[![Rust Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://docs.rs/actix-middleware-macro/)\n\nA macro to generate actix-web middleware. Useful for the times when you can't be bothered to figure it out yourself for the 100th time.\n\n\n## Usage\n\n```rust\nuse actix_web::web;\n\nuse super::*;\n\ncreate_middleware!(\n    TimingCorsHeaders,\n    |ctx: \u0026MiddlewareTransform\u003cS\u003e, req: ServiceRequest| {\n        use actix_web::http::header::{HeaderName, HeaderValue};\n        use chrono::Utc;\n\n        let start = Utc::now();\n\n        let fut = ctx.service.call(req);\n        Box::pin(async move {\n            let mut res = fut.await?;\n            let duration = Utc::now() - start;\n            res.headers_mut().insert(\n                HeaderName::from_static(\"x-app-time-ms\"),\n                HeaderValue::from_str(\u0026format!(\"{}\", duration.num_milliseconds()))?,\n            );\n\n            Ok(res)\n        })\n    }\n);\n\n#[actix_web::test]\nasync fn works() {\n    let _server = tokio::spawn(async {\n        actix_web::HttpServer::new(|| {\n            actix_web::App::new()\n                .default_service(web::to(|| async { actix_web::HttpResponse::Ok() }))\n                .wrap(timing_cors_headers_middleware::Middleware)\n        })\n        .bind(\"127.1:8080\")\n        .unwrap()\n        .run()\n        .await\n        .unwrap();\n    });\n\n    tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;\n\n    let response = ureq::get(\"http://127.1:8080\").call().unwrap();\n    assert!(response.header(\"x-app-time-ms\").is_some());\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmustakimali%2Factix-middleware-macro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmustakimali%2Factix-middleware-macro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmustakimali%2Factix-middleware-macro/lists"}