diff --git a/Cargo.lock b/Cargo.lock index 847debdc..474dc1be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3394,7 +3394,7 @@ dependencies = [ "convert_case", "csv", "futures-util", - "reqwest", + "hyper", "serde", "tokio", "tracing", diff --git a/crates/iana-codegen/Cargo.toml b/crates/iana-codegen/Cargo.toml index 4472ef41..9d445b12 100644 --- a/crates/iana-codegen/Cargo.toml +++ b/crates/iana-codegen/Cargo.toml @@ -12,8 +12,8 @@ camino = "1.1.4" convert_case = "0.6.0" csv = "1.2.1" futures-util = "0.3.28" -reqwest = { version = "0.11.16", features = ["blocking", "rustls-tls"], default-features = false } +hyper = { version = "0.14.16", features = ["tcp", "client", "http1"] } serde = { version = "1.0.160", features = ["derive"] } -tokio = { version = "1.27.0", features = ["full"] } +tokio = { version = "1.27.0", features = ["macros", "rt-multi-thread", "fs", "io-util"] } tracing = "0.1.37" tracing-subscriber = "0.3.16" diff --git a/crates/iana-codegen/src/jose.rs b/crates/iana-codegen/src/jose.rs index a23561f7..ee2f409a 100644 --- a/crates/iana-codegen/src/jose.rs +++ b/crates/iana-codegen/src/jose.rs @@ -62,7 +62,7 @@ pub struct WebEncryptionSignatureAlgorithm { impl EnumEntry for WebEncryptionSignatureAlgorithm { const URL: &'static str = - "https://www.iana.org/assignments/jose/web-signature-encryption-algorithms.csv"; + "http://www.iana.org/assignments/jose/web-signature-encryption-algorithms.csv"; const SECTIONS: &'static [Section] = &[ s( "JsonWebSignatureAlg", @@ -126,7 +126,7 @@ pub struct WebEncryptionCompressionAlgorithm { impl EnumEntry for WebEncryptionCompressionAlgorithm { const URL: &'static str = - "https://www.iana.org/assignments/jose/web-encryption-compression-algorithms.csv"; + "http://www.iana.org/assignments/jose/web-encryption-compression-algorithms.csv"; const SECTIONS: &'static [Section] = &[s( "JsonWebEncryptionCompressionAlgorithm", "JSON Web Encryption Compression Algorithm", @@ -161,7 +161,7 @@ pub struct WebKeyType { } impl EnumEntry for WebKeyType { - const URL: &'static str = "https://www.iana.org/assignments/jose/web-key-types.csv"; + const URL: &'static str = "http://www.iana.org/assignments/jose/web-key-types.csv"; const SECTIONS: &'static [Section] = &[s("JsonWebKeyType", "JSON Web Key Type")]; fn key(&self) -> Option<&'static str> { @@ -193,7 +193,7 @@ pub struct WebKeyEllipticCurve { } impl EnumEntry for WebKeyEllipticCurve { - const URL: &'static str = "https://www.iana.org/assignments/jose/web-key-elliptic-curve.csv"; + const URL: &'static str = "http://www.iana.org/assignments/jose/web-key-elliptic-curve.csv"; const SECTIONS: &'static [Section] = &[ s( "JsonWebKeyEcEllipticCurve", @@ -236,7 +236,7 @@ pub struct WebKeyUse { } impl EnumEntry for WebKeyUse { - const URL: &'static str = "https://www.iana.org/assignments/jose/web-key-use.csv"; + const URL: &'static str = "http://www.iana.org/assignments/jose/web-key-use.csv"; const SECTIONS: &'static [Section] = &[s("JsonWebKeyUse", "JSON Web Key Use")]; fn key(&self) -> Option<&'static str> { @@ -266,7 +266,7 @@ pub struct WebKeyOperation { } impl EnumEntry for WebKeyOperation { - const URL: &'static str = "https://www.iana.org/assignments/jose/web-key-operations.csv"; + const URL: &'static str = "http://www.iana.org/assignments/jose/web-key-operations.csv"; const SECTIONS: &'static [Section] = &[s("JsonWebKeyOperation", "JSON Web Key Operation")]; fn key(&self) -> Option<&'static str> { diff --git a/crates/iana-codegen/src/main.rs b/crates/iana-codegen/src/main.rs index f3303be2..ca2128b0 100644 --- a/crates/iana-codegen/src/main.rs +++ b/crates/iana-codegen/src/main.rs @@ -19,10 +19,11 @@ use std::{collections::HashMap, fmt::Display, sync::Arc}; use camino::{Utf8Path, Utf8PathBuf}; -use reqwest::Client; use tokio::io::AsyncWriteExt; use tracing::Level; +type Client = hyper::Client; + mod gen; pub mod jose; pub mod oauth; @@ -208,7 +209,7 @@ async fn main() -> anyhow::Result<()> { .pretty() .init(); - let client = Client::builder().user_agent("iana-parser/0.0.1").build()?; + let client = Client::new(); let client = Arc::new(client); let iana_crate_root = Utf8Path::new("crates/iana/"); diff --git a/crates/iana-codegen/src/oauth.rs b/crates/iana-codegen/src/oauth.rs index e21b6768..262b470c 100644 --- a/crates/iana-codegen/src/oauth.rs +++ b/crates/iana-codegen/src/oauth.rs @@ -35,7 +35,7 @@ pub struct AccessTokenType { } impl EnumEntry for AccessTokenType { - const URL: &'static str = "https://www.iana.org/assignments/oauth-parameters/token-types.csv"; + const URL: &'static str = "http://www.iana.org/assignments/oauth-parameters/token-types.csv"; const SECTIONS: &'static [Section] = &[s("OAuthAccessTokenType", "OAuth Access Token Type")]; fn key(&self) -> Option<&'static str> { @@ -59,7 +59,7 @@ pub struct AuthorizationEndpointResponseType { } impl EnumEntry for AuthorizationEndpointResponseType { - const URL: &'static str = "https://www.iana.org/assignments/oauth-parameters/endpoint.csv"; + const URL: &'static str = "http://www.iana.org/assignments/oauth-parameters/endpoint.csv"; const SECTIONS: &'static [Section] = &[s( "OAuthAuthorizationEndpointResponseType", "OAuth Authorization Endpoint Response Type", @@ -98,7 +98,7 @@ pub struct TokenTypeHint { impl EnumEntry for TokenTypeHint { const URL: &'static str = - "https://www.iana.org/assignments/oauth-parameters/token-type-hint.csv"; + "http://www.iana.org/assignments/oauth-parameters/token-type-hint.csv"; const SECTIONS: &'static [Section] = &[s("OAuthTokenTypeHint", "OAuth Token Type Hint")]; fn key(&self) -> Option<&'static str> { @@ -112,7 +112,7 @@ impl EnumEntry for TokenTypeHint { impl EnumEntry for TokenEndpointAuthenticationMethod { const URL: &'static str = - "https://www.iana.org/assignments/oauth-parameters/token-endpoint-auth-method.csv"; + "http://www.iana.org/assignments/oauth-parameters/token-endpoint-auth-method.csv"; const SECTIONS: &'static [Section] = &[s( "OAuthClientAuthenticationMethod", "OAuth Token Endpoint Authentication Method", @@ -140,7 +140,7 @@ pub struct PkceCodeChallengeMethod { impl EnumEntry for PkceCodeChallengeMethod { const URL: &'static str = - "https://www.iana.org/assignments/oauth-parameters/pkce-code-challenge-method.csv"; + "http://www.iana.org/assignments/oauth-parameters/pkce-code-challenge-method.csv"; const SECTIONS: &'static [Section] = &[s("PkceCodeChallengeMethod", "PKCE Code Challenge Method")]; diff --git a/crates/iana-codegen/src/traits.rs b/crates/iana-codegen/src/traits.rs index ba95d820..7c900608 100644 --- a/crates/iana-codegen/src/traits.rs +++ b/crates/iana-codegen/src/traits.rs @@ -15,9 +15,11 @@ use anyhow::Context; use async_trait::async_trait; use convert_case::{Case, Casing}; -use reqwest::Client; +use hyper::http; use serde::de::DeserializeOwned; +use super::Client; + #[derive(Debug, Clone)] pub struct Section { pub key: &'static str, @@ -72,12 +74,19 @@ pub trait EnumEntry: DeserializeOwned + Send + Sync { async fn fetch(client: &Client) -> anyhow::Result> { tracing::info!("Fetching CSV"); - let body = client - .get(Self::URL) - .send() + let request = http::Request::get(Self::URL) + .header("User-Agent", "mas-iana-codegen/0.1") + .body(hyper::Body::empty())?; + + let response = client + .request(request) .await - .context(format!("can't the CSV at {}", Self::URL))? - .bytes() + .context(format!("can't the CSV at {}", Self::URL))?; + + let status = response.status(); + anyhow::ensure!(status.is_success(), "HTTP status code is not 200: {status}"); + + let body = hyper::body::to_bytes(response.into_body()) .await .context(format!("can't the CSV body at {}", Self::URL))?; diff --git a/crates/iana/src/jose.rs b/crates/iana/src/jose.rs index 99f031e5..37411c3c 100644 --- a/crates/iana/src/jose.rs +++ b/crates/iana/src/jose.rs @@ -19,7 +19,7 @@ /// JSON Web Signature "alg" parameter /// -/// Source: +/// Source: #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum JsonWebSignatureAlg { @@ -365,7 +365,7 @@ impl schemars::JsonSchema for JsonWebSignatureAlg { /// JSON Web Encryption "alg" parameter /// -/// Source: +/// Source: #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum JsonWebEncryptionAlg { @@ -783,7 +783,7 @@ impl schemars::JsonSchema for JsonWebEncryptionAlg { /// JSON Web Encryption "enc" parameter /// -/// Source: +/// Source: #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum JsonWebEncryptionEnc { @@ -967,7 +967,7 @@ impl schemars::JsonSchema for JsonWebEncryptionEnc { /// JSON Web Encryption Compression Algorithm /// -/// Source: +/// Source: #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum JsonWebEncryptionCompressionAlgorithm { @@ -1061,7 +1061,7 @@ impl schemars::JsonSchema for JsonWebEncryptionCompressionAlgorithm { /// JSON Web Key Type /// -/// Source: +/// Source: #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum JsonWebKeyType { @@ -1209,7 +1209,7 @@ impl schemars::JsonSchema for JsonWebKeyType { /// JSON Web Key EC Elliptic Curve /// -/// Source: +/// Source: #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum JsonWebKeyEcEllipticCurve { @@ -1357,7 +1357,7 @@ impl schemars::JsonSchema for JsonWebKeyEcEllipticCurve { /// JSON Web Key OKP Elliptic Curve /// -/// Source: +/// Source: #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum JsonWebKeyOkpEllipticCurve { @@ -1505,7 +1505,7 @@ impl schemars::JsonSchema for JsonWebKeyOkpEllipticCurve { /// JSON Web Key Use /// -/// Source: +/// Source: #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum JsonWebKeyUse { @@ -1617,7 +1617,7 @@ impl schemars::JsonSchema for JsonWebKeyUse { /// JSON Web Key Operation /// -/// Source: +/// Source: #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum JsonWebKeyOperation { diff --git a/crates/iana/src/oauth.rs b/crates/iana/src/oauth.rs index 677a4df7..76b9b365 100644 --- a/crates/iana/src/oauth.rs +++ b/crates/iana/src/oauth.rs @@ -19,7 +19,7 @@ /// OAuth Access Token Type /// -/// Source: +/// Source: #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum OAuthAccessTokenType { @@ -128,7 +128,7 @@ impl schemars::JsonSchema for OAuthAccessTokenType { /// OAuth Authorization Endpoint Response Type /// -/// Source: +/// Source: #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum OAuthAuthorizationEndpointResponseType { /// `code` @@ -287,7 +287,7 @@ impl schemars::JsonSchema for OAuthAuthorizationEndpointResponseType { /// OAuth Token Type Hint /// -/// Source: +/// Source: #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum OAuthTokenTypeHint { @@ -396,7 +396,7 @@ impl schemars::JsonSchema for OAuthTokenTypeHint { /// OAuth Token Endpoint Authentication Method /// -/// Source: +/// Source: #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum OAuthClientAuthenticationMethod { @@ -549,7 +549,7 @@ impl schemars::JsonSchema for OAuthClientAuthenticationMethod { /// PKCE Code Challenge Method /// -/// Source: +/// Source: #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum PkceCodeChallengeMethod {