faucet-stream 0.1.4

A declarative, config-driven REST API client with pluggable authentication, pagination, and JSONPath extraction
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
//! API key header authentication.

use crate::error::FaucetError;
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};

pub fn apply(headers: &mut HeaderMap, header: &str, value: &str) -> Result<(), FaucetError> {
    let name = HeaderName::from_bytes(header.as_bytes())
        .map_err(|e| FaucetError::Auth(format!("invalid header name '{header}': {e}")))?;
    let val = HeaderValue::from_str(value)
        .map_err(|e| FaucetError::Auth(format!("invalid header value: {e}")))?;
    headers.insert(name, val);
    Ok(())
}