Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit cd7f69e

Browse files
committed
Update mas-iana-codegen to use reqwest
1 parent 925f85c commit cd7f69e

File tree

4 files changed

+192
-19
lines changed

4 files changed

+192
-19
lines changed

Cargo.lock

Lines changed: 177 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/iana-codegen/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ camino.workspace = true
1818
convert_case = "0.6.0"
1919
csv = "1.3.0"
2020
futures-util = "0.3.30"
21-
hyper.workspace = true
21+
reqwest = "0.12.5"
2222
serde.workspace = true
23-
tokio.workspace= true
23+
tokio.workspace = true
2424
tracing.workspace = true
2525
tracing-subscriber.workspace = true

crates/iana-codegen/src/main.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::{collections::HashMap, fmt::Display, sync::Arc};
15+
use std::{collections::HashMap, fmt::Display};
1616

1717
use camino::{Utf8Path, Utf8PathBuf};
18+
use reqwest::Client;
1819
use tokio::io::AsyncWriteExt;
1920
use tracing::Level;
2021

21-
type Client = hyper::Client<hyper::client::HttpConnector>;
22-
2322
mod gen;
2423
pub mod jose;
2524
pub mod oauth;
2625
pub mod traits;
2726

2827
#[derive(Debug)]
2928
struct File {
30-
client: Arc<Client>,
29+
client: Client,
3130
registry_name: &'static str,
3231
registry_url: &'static str,
3332
sections: Vec<Section>,
@@ -42,7 +41,7 @@ fn resolve_path(relative: impl AsRef<Utf8Path>) -> Utf8PathBuf {
4241

4342
impl File {
4443
#[tracing::instrument(skip(client))]
45-
fn new(registry_name: &'static str, registry_url: &'static str, client: Arc<Client>) -> Self {
44+
fn new(registry_name: &'static str, registry_url: &'static str, client: Client) -> Self {
4645
tracing::info!("Generating file from IANA registry");
4746
Self {
4847
client,
@@ -142,7 +141,7 @@ use self::traits::{EnumEntry, EnumMember, Section};
142141

143142
#[tracing::instrument(skip_all, fields(%path))]
144143
async fn generate_jose(
145-
client: &Arc<Client>,
144+
client: &Client,
146145
path: impl AsRef<Utf8Path> + std::fmt::Display,
147146
) -> anyhow::Result<()> {
148147
let path = resolve_path(path);
@@ -173,7 +172,7 @@ async fn generate_jose(
173172

174173
#[tracing::instrument(skip_all, fields(%path))]
175174
async fn generate_oauth(
176-
client: &Arc<Client>,
175+
client: &Client,
177176
path: impl AsRef<Utf8Path> + std::fmt::Display,
178177
) -> anyhow::Result<()> {
179178
let path = resolve_path(path);
@@ -182,7 +181,7 @@ async fn generate_oauth(
182181
let file = File::new(
183182
"OAuth Parameters",
184183
"https://www.iana.org/assignments/jose/jose.xhtml",
185-
client.clone(),
184+
client,
186185
)
187186
.load::<oauth::AccessTokenType>()
188187
.await?
@@ -208,7 +207,6 @@ async fn main() -> anyhow::Result<()> {
208207
.init();
209208

210209
let client = Client::new();
211-
let client = Arc::new(client);
212210

213211
let iana_crate_root = Utf8Path::new("crates/iana/");
214212

crates/iana-codegen/src/traits.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use anyhow::Context;
1616
use async_trait::async_trait;
1717
use convert_case::{Case, Casing};
18-
use hyper::http;
1918
use serde::de::DeserializeOwned;
2019

2120
use super::Client;
@@ -74,23 +73,23 @@ pub trait EnumEntry: DeserializeOwned + Send + Sync {
7473

7574
async fn fetch(client: &Client) -> anyhow::Result<Vec<(&'static str, EnumMember)>> {
7675
tracing::info!("Fetching CSV");
77-
let request = http::Request::get(Self::URL)
78-
.header("User-Agent", "mas-iana-codegen/0.1")
79-
.body(hyper::Body::empty())?;
8076

8177
let response = client
82-
.request(request)
78+
.get(Self::URL)
79+
.header("User-Agent", "mas-iana-codegen/0.1")
80+
.send()
8381
.await
8482
.context(format!("can't the CSV at {}", Self::URL))?;
8583

8684
let status = response.status();
8785
anyhow::ensure!(status.is_success(), "HTTP status code is not 200: {status}");
8886

89-
let body = hyper::body::to_bytes(response.into_body())
87+
let body = response
88+
.text()
9089
.await
9190
.context(format!("can't the CSV body at {}", Self::URL))?;
9291

93-
let parsed: Result<Vec<_>, _> = csv::Reader::from_reader(body.as_ref())
92+
let parsed: Result<Vec<_>, _> = csv::Reader::from_reader(body.as_bytes())
9493
.into_deserialize()
9594
.filter_map(|item: Result<Self, _>| {
9695
item.map(|item| {

0 commit comments

Comments
 (0)