Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,9 @@ impl Api {
handle.transfer_encoding(self.config.allow_transfer_encoding())?;

let env = self.config.get_pipeline_env();
let custom_header = self.config.get_custom_header();

ApiRequest::create(handle, &method, &url, auth, env)
ApiRequest::create(handle, &method, &url, auth, env, custom_header)
}

/// Convenience method that performs a `GET` request.
Expand Down Expand Up @@ -1519,6 +1520,7 @@ impl ApiRequest {
url: &str,
auth: Option<&Auth>,
pipeline_env: Option<String>,
custom_header: Option<String>,
) -> ApiResult<Self> {
debug!("request {} {}", method, url);

Expand All @@ -1539,6 +1541,10 @@ impl ApiRequest {
}
}

if let Some(custom_header) = custom_header {
headers.append(&custom_header).ok();
}

match method {
Method::Get => handle.get(true)?,
Method::Head => {
Expand Down
9 changes: 9 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,15 @@ impl Config {
})
}

/// Return the custom header added to all requests.
pub fn get_custom_header(&self) -> Option<String> {
env::var("CUSTOM_HEADER").ok().or_else(|| {
self.ini
.get_from(Some("defaults"), "custom_header")
.map(str::to_owned)
})
}

/// Returns the defaults for org and project.
pub fn get_org_and_project_defaults(&self) -> (Option<String>, Option<String>) {
(
Expand Down