Skip to content

Commit a8a918e

Browse files
committed
rust: use reqwest for release artifact upload
Something about the low-level hyper code wasn't working. So I just switched to reqwest, which worked on the first try.
1 parent 42c2b46 commit a8a918e

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed

src/github.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
use bytes::Bytes;
6-
use std::str::FromStr;
7-
use tokio::net::TcpStream;
85
use {
96
crate::release::{produce_install_only, RELEASE_TRIPLES},
107
anyhow::{anyhow, Result},
8+
bytes::Bytes,
119
clap::ArgMatches,
1210
futures::StreamExt,
13-
http::Method,
1411
octocrab::{
1512
models::{repos::Release, workflows::WorkflowListArtifact},
1613
params::actions::ArchiveFormat,
@@ -69,31 +66,19 @@ async fn upload_release_artifact(
6966
// Octocrab doesn't yet support release artifact upload. And the low-level HTTP API
7067
// forces the use of strings on us. So we have to make our own HTTP client.
7168

72-
let uri = hyper::Uri::from_str(url.as_str())?;
73-
74-
let request = http::request::Builder::new()
75-
.method(Method::PUT)
76-
.uri(uri)
77-
.header("Authorization", format!("Bearer {auth_token}"))
78-
.header("Content-Length", data.len())
79-
.header("Content-Type", "application/x-tar")
80-
.body(http_body_util::Full::new(data))?;
81-
8269
if dry_run {
8370
return Ok(());
8471
}
8572

86-
let host = url.host().ok_or_else(|| anyhow!("no host in URL"))?;
87-
let port = url.port().unwrap_or(443);
88-
let address = format!("{host}:{port}");
89-
90-
let stream = TcpStream::connect(address).await?;
91-
let io = hyper_util::rt::TokioIo::new(stream);
92-
let (mut sender, conn) = hyper::client::conn::http1::handshake(io).await?;
93-
94-
conn.await?;
95-
96-
let response = sender.send_request(request).await?;
73+
let response = reqwest::Client::builder()
74+
.build()?
75+
.put(url)
76+
.header("Authorization", format!("Bearer {auth_token}"))
77+
.header("Content-Length", data.len())
78+
.header("Content-Type", "application/x-tar")
79+
.body(data)
80+
.send()
81+
.await?;
9782

9883
if !response.status().is_success() {
9984
return Err(anyhow!("HTTP {}", response.status()));

0 commit comments

Comments
 (0)