MCPcopy Create free account
hub / github.com/base/base / new_http_with_headers

Method new_http_with_headers

crates/execution/rpc/src/sequencer.rs:86–116  ·  view source on GitHub ↗

Creates an HTTP sequencer client synchronously, with optional `header=value` headers. # Errors Returns an error for a non-HTTP URL, invalid headers, or HTTP client construction.

(
        sequencer_endpoint: impl Into<String>,
        headers: Vec<String>,
    )

Source from the content-addressed store, hash-verified

84 ///
85 /// Returns an error for a non-HTTP URL, invalid headers, or HTTP client construction.
86 pub fn new_http_with_headers(
87 sequencer_endpoint: impl Into<String>,
88 headers: Vec<String>,
89 ) -> Result<Self, Error> {
90 let sequencer_endpoint = sequencer_endpoint.into();
91 if !matches!(
92 BuiltInConnectionString::from_str(&sequencer_endpoint)?,
93 BuiltInConnectionString::Http(_)
94 ) {
95 return Err(Error::InvalidScheme(sequencer_endpoint));
96 }
97 let mut builder = alloy_reqwest::Client::builder().use_rustls_tls();
98 if !headers.is_empty() {
99 let mut header_map = alloy_reqwest::header::HeaderMap::new();
100 for header in headers {
101 if let Some((key, value)) = header.split_once('=') {
102 header_map.insert(
103 key.trim()
104 .parse::<alloy_reqwest::header::HeaderName>()
105 .map_err(|err| Error::InvalidHeader(err.to_string()))?,
106 value
107 .trim()
108 .parse::<alloy_reqwest::header::HeaderValue>()
109 .map_err(|err| Error::InvalidHeader(err.to_string()))?,
110 );
111 }
112 }
113 builder = builder.default_headers(header_map);
114 }
115 Self::with_http_client(sequencer_endpoint, builder.build()?)
116 }
117
118 /// Creates a new [`SequencerClient`] with http transport with the given http client.
119 pub fn with_http_client(

Callers

nothing calls this directly

Calls 5

builderFunction · 0.50
newFunction · 0.50
is_emptyMethod · 0.45
insertMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected