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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "axiom-rs"
version = "0.11.2"
version = "0.11.3"
authors = ["Arne Bahlo <arne@axiom.co>"]
edition = "2018"
rust-version = "1.60"
Expand Down
46 changes: 46 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ use crate::{
/// API URL is the URL for the Axiom Cloud API.
static API_URL: &str = "https://api.axiom.co";

/// Request options that can be passed to some handlers.
#[derive(Debug, Default)]
pub struct RequestOptions {
additional_headers: HeaderMap,
}

/// The client is the entrypoint of the whole SDK.
///
/// You can create it using [`Client::builder`] or [`Client::new`].
Expand Down Expand Up @@ -192,11 +198,51 @@ impl Client {
content_type: ContentType,
content_encoding: ContentEncoding,
) -> Result<IngestStatus>
where
N: Into<String> + FmtDebug,
P: Into<Bytes>,
{
self.ingest_bytes_opt(
dataset_name,
payload,
content_type,
content_encoding,
RequestOptions::default(),
)
.await
}

/// Like `ingest_bytes`, but takes a `RequestOptions`, which allows you to
/// customize your request further.
/// Note that any content-type and content-type headers in `RequestOptions`
/// will be overwritten by the given arguments.
///
/// # Errors
///
/// Returns an error if the HTTP request or JSON deserializing fails.
#[instrument(skip(self, payload))]
pub async fn ingest_bytes_opt<N, P>(
&self,
dataset_name: N,
payload: P,
content_type: ContentType,
content_encoding: ContentEncoding,
request_options: RequestOptions,
) -> Result<IngestStatus>
where
N: Into<String> + FmtDebug,
P: Into<Bytes>,
{
let mut headers = HeaderMap::new();

// Add headers from request options
for (key, value) in request_options.additional_headers {
if let Some(key) = key {
headers.insert(key, value);
}
}

// Add content-type, content-encoding
headers.insert(header::CONTENT_TYPE, content_type.into());
headers.insert(header::CONTENT_ENCODING, content_encoding.into());

Expand Down
Loading