From 9328b299a95e1d7d0afc034e1448200e39313dbf Mon Sep 17 00:00:00 2001 From: kpcyrd Date: Thu, 7 Mar 2024 22:31:28 +0100 Subject: [PATCH] Add cf.as_organization function (#461) --- worker-sys/src/types/incoming_request_cf_properties.rs | 3 +++ worker/src/cf.rs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/worker-sys/src/types/incoming_request_cf_properties.rs b/worker-sys/src/types/incoming_request_cf_properties.rs index 7e745422..057492db 100644 --- a/worker-sys/src/types/incoming_request_cf_properties.rs +++ b/worker-sys/src/types/incoming_request_cf_properties.rs @@ -14,6 +14,9 @@ extern "C" { #[wasm_bindgen(method, getter)] pub fn asn(this: &IncomingRequestCfProperties) -> u32; + #[wasm_bindgen(method, getter, js_name=asOrganization)] + pub fn as_organization(this: &IncomingRequestCfProperties) -> String; + #[wasm_bindgen(method, getter)] pub fn country(this: &IncomingRequestCfProperties) -> Option; diff --git a/worker/src/cf.rs b/worker/src/cf.rs index e41187a1..4079ac92 100644 --- a/worker/src/cf.rs +++ b/worker/src/cf.rs @@ -18,6 +18,11 @@ impl Cf { self.inner.asn() } + /// The Autonomous System organization name of the request, e.g. `Cloudflare, Inc.` + pub fn as_organization(&self) -> String { + self.inner.as_organization() + } + /// The two-letter country code of origin for the request. /// This is the same value as that provided in the CF-IPCountry header, e.g. `"US"` pub fn country(&self) -> Option {