Skip to content

Commit

Permalink
fix: always set header when creating a new stream (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Oct 22, 2023
1 parent ab09dd7 commit 5c50f31
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions crates/mev-share-sse/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use futures_util::{
Stream, TryFutureExt, TryStreamExt,
};
use pin_project_lite::pin_project;
use reqwest::header::{self, HeaderMap, HeaderValue};
use reqwest::header::{self, HeaderValue};
use serde::{de::DeserializeOwned, Serialize};
use std::{
future::Future,
Expand Down Expand Up @@ -166,15 +166,7 @@ impl EventClient {

impl Default for EventClient {
fn default() -> Self {
Self::new(
reqwest::Client::builder()
.default_headers(HeaderMap::from_iter([
(header::ACCEPT, HeaderValue::from_static("text/event-stream")),
(header::CACHE_CONTROL, HeaderValue::from_static("no-cache")),
]))
.build()
.expect("Reqwest client build failed, TLS backend not available?"),
)
Self::new(Default::default())
}
}

Expand Down Expand Up @@ -352,12 +344,16 @@ impl<T: DeserializeOwned> Stream for ActiveEventStream<T> {
}
}

/// Creates a new SSE stream.
async fn new_stream<T: DeserializeOwned, S: Serialize>(
client: &reqwest::Client,
endpoint: &str,
query: Option<S>,
) -> reqwest::Result<ActiveEventStream<T>> {
let mut builder = client.get(endpoint);
let mut builder = client
.get(endpoint)
.header(header::ACCEPT, HeaderValue::from_static("text/event-stream"))
.header(header::CACHE_CONTROL, HeaderValue::from_static("no-cache"));
if let Some(query) = query {
builder = builder.query(&query);
}
Expand Down Expand Up @@ -409,10 +405,10 @@ mod tests {
const HISTORY_INFO_V1: &str = "https://mev-share.flashbots.net/api/v1/history/info";

fn init_tracing() {
tracing_subscriber::registry()
let _ = tracing_subscriber::registry()
.with(fmt::layer())
.with(EnvFilter::from_default_env())
.init();
.try_init();
}

#[tokio::test]
Expand Down

0 comments on commit 5c50f31

Please sign in to comment.