Skip to content

Commit

Permalink
Remove hyperx dep; Manually inspect 'Link' header (#258)
Browse files Browse the repository at this point in the history
* Remove hyperx dep; Manually inspect 'Link' header

* Remove unnecessary regex usage
  • Loading branch information
lpotthast authored Mar 21, 2023
1 parent 9292aa4 commit 7694573
Show file tree
Hide file tree
Showing 7 changed files with 401 additions and 42 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ serde = { version = "1.0.126", features = ["derive"] }
serde_json = "1.0.64"
serde_path_to_error = "0.1.4"
async-trait = "0.1.50"
chrono = { version = "0.4.19", default-features = false, features = ["serde", "clock"] }
chrono = { version = "0.4.19", default-features = false, features = [
"serde",
"clock",
] }
url = { version = "2.2.2", features = ["serde"] }
hyperx = "1.3.0"
snafu = { version = "0.7", features = ["backtraces"] }
once_cell = "1.7.2"
arc-swap = "1.3.0"
Expand Down
9 changes: 2 additions & 7 deletions src/api/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::models::{
workflows::WorkflowDispatch, workflows::WorkflowListArtifact, ArtifactId, RepositoryId, RunId,
};
use crate::{params, FromResponse, Octocrab, Page};
use hyperx::header::{ETag, IfNoneMatch, TypedHeaders};
use reqwest::{header::HeaderMap, Method, StatusCode};

pub struct ListWorkflowRunArtifacts<'octo> {
Expand Down Expand Up @@ -60,15 +59,11 @@ impl<'octo> ListWorkflowRunArtifacts<'octo> {
);
let mut headers = HeaderMap::new();
if let Some(etag) = self.etag {
headers.encode(&IfNoneMatch::Items(vec![etag]));
EntityTag::insert_if_none_match_header(&mut headers, etag)?;
}
let builder = self.crab.client.request(Method::GET, &url).headers(headers);
let response = self.crab.execute(builder).await?;
let etag = response
.headers()
.decode::<ETag>()
.ok()
.map(|ETag(tag)| tag);
let etag = EntityTag::extract_from_response(&response);
if response.status() == StatusCode::NOT_MODIFIED {
Ok(Etagged { etag, value: None })
} else {
Expand Down
9 changes: 2 additions & 7 deletions src/api/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{
models::events,
FromResponse, Octocrab, Page,
};
use hyperx::header::{ETag, IfNoneMatch, TypedHeaders};
use reqwest::{header::HeaderMap, Method, StatusCode};

pub struct EventsBuilder<'octo> {
Expand Down Expand Up @@ -60,7 +59,7 @@ impl<'octo> EventsBuilder<'octo> {
let url = format!("{base_url}events", base_url = self.crab.base_url);
let mut headers = HeaderMap::new();
if let Some(etag) = self.headers.etag {
headers.encode(&IfNoneMatch::Items(vec![etag]));
EntityTag::insert_if_none_match_header(&mut headers, etag)?;
}
let builder = self
.crab
Expand All @@ -69,11 +68,7 @@ impl<'octo> EventsBuilder<'octo> {
.headers(headers)
.query(&self.params);
let response = self.crab.execute(builder).await?;
let etag = response
.headers()
.decode::<ETag>()
.ok()
.map(|ETag(tag)| tag);
let etag = EntityTag::extract_from_response(&response);
if response.status() == StatusCode::NOT_MODIFIED {
Ok(Etagged { etag, value: None })
} else {
Expand Down
9 changes: 2 additions & 7 deletions src/api/repos/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::{
repos::RepoHandler,
FromResponse, Page,
};
use hyperx::header::{ETag, IfNoneMatch, TypedHeaders};
use reqwest::{header::HeaderMap, Method, StatusCode};

pub struct ListRepoEventsBuilder<'octo, 'handler> {
Expand Down Expand Up @@ -66,7 +65,7 @@ impl<'octo, 'handler> ListRepoEventsBuilder<'octo, 'handler> {
);
let mut headers = HeaderMap::new();
if let Some(etag) = self.headers.etag {
headers.encode(&IfNoneMatch::Items(vec![etag]));
EntityTag::insert_if_none_match_header(&mut headers, etag)?;
}
let builder = self
.handler
Expand All @@ -76,11 +75,7 @@ impl<'octo, 'handler> ListRepoEventsBuilder<'octo, 'handler> {
.headers(headers)
.query(&self.params);
let response = self.handler.crab.execute(builder).await?;
let etag = response
.headers()
.decode::<ETag>()
.ok()
.map(|ETag(tag)| tag);
let etag = EntityTag::extract_from_response(&response);
if response.status() == StatusCode::NOT_MODIFIED {
Ok(Etagged { etag, value: None })
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ pub enum Error {
source: url::ParseError,
backtrace: Backtrace,
},
InvalidHeaderValue {
source: reqwest::header::InvalidHeaderValue,
backtrace: Backtrace,
},
#[snafu(display("HTTP Error: {}\n\nFound at {}", source, backtrace))]
Http {
source: reqwest::Error,
Expand Down
Loading

0 comments on commit 7694573

Please sign in to comment.