I'm in a need of consuming an eventsource API, but it's a private one, where I need to pass some auth headers, specifically the Authorization one, and some more.
I had a look into these "two" crates, but neither of them explains how to pass some headers, has someone passed by something related, or knows how to set it up in these crates?
use eventsource::reqwest::Client as EventSourceClient;
use reqwest::{blocking::Client as ReqwestClient, header::HeaderMap};
let mut headers = HeaderMap::new();
headers.insert("Authorization", "Basic Zm9vOmJhcg==".parse()?);
headers.insert("X-Foo", "bar".parse()?);
let client = ReqwestClient::builder().default_headers(headers).build()?;
let client = EventSourceClient::new_with_client("https://example.com/".parse()?, client);
It can also be done in reqwest-eventsource by using a RequestBuilder:
use reqwest::{header::HeaderMap, Client};
use reqwest_eventsource::RequestBuilderExt;
let mut headers = HeaderMap::new();
headers.insert("Authorization", "Basic Zm9vOmJhcg==".parse()?);
headers.insert("X-Foo", "bar".parse()?);
let client = Client::builder().default_headers(headers).build()?;
let event_source = client.get("https://example.com/").eventsource()?;
/* or alternatively: */
use reqwest::Client;
use reqwest_eventsource::RequestBuilderExt;
let event_source = Client::new()
.get("https://example.com/")
.header("Authorization", "Basic Zm9vOmJhcg==")
.header("X-Foo", "bar")
.eventsource()?;