Skip to content

Commit 2499bd5

Browse files
committed
Made some strings static
1 parent 8ebfbd0 commit 2499bd5

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

crates/common/src/utils.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ use crate::{
4646
types::{BlsPublicKey, Chain, Jwt, JwtClaims, ModuleId},
4747
};
4848

49-
const APPLICATION_JSON: &str = "application/json";
50-
const APPLICATION_OCTET_STREAM: &str = "application/octet-stream";
51-
const WILDCARD: &str = "*/*";
49+
pub const APPLICATION_JSON: &str = "application/json";
50+
pub const APPLICATION_OCTET_STREAM: &str = "application/octet-stream";
51+
pub const WILDCARD: &str = "*/*";
5252

5353
const MILLIS_PER_SECOND: u64 = 1_000;
5454
pub const CONSENSUS_VERSION_HEADER: &str = "Eth-Consensus-Version";
@@ -498,21 +498,28 @@ pub enum EncodingType {
498498
Ssz,
499499
}
500500

501-
impl std::fmt::Display for EncodingType {
502-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
501+
impl EncodingType {
502+
/// Get the content type string for the encoding type
503+
pub fn content_type(&self) -> &str {
503504
match self {
504-
EncodingType::Json => write!(f, "application/json"),
505-
EncodingType::Ssz => write!(f, "application/octet-stream"),
505+
EncodingType::Json => APPLICATION_JSON,
506+
EncodingType::Ssz => APPLICATION_OCTET_STREAM,
506507
}
507508
}
508509
}
509510

511+
impl std::fmt::Display for EncodingType {
512+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
513+
write!(f, "{}", self.content_type())
514+
}
515+
}
516+
510517
impl FromStr for EncodingType {
511518
type Err = String;
512519
fn from_str(value: &str) -> Result<Self, Self::Err> {
513520
match value.to_ascii_lowercase().as_str() {
514-
"application/json" | "" => Ok(EncodingType::Json),
515-
"application/octet-stream" => Ok(EncodingType::Ssz),
521+
APPLICATION_JSON | "" => Ok(EncodingType::Json),
522+
APPLICATION_OCTET_STREAM => Ok(EncodingType::Ssz),
516523
_ => Err(format!("unsupported encoding type: {value}")),
517524
}
518525
}

crates/pbs/src/mev_boost/get_header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ async fn send_one_get_header(
412412
// Also resets the start request timer
413413
original_headers.remove(ACCEPT);
414414
original_headers
415-
.insert(ACCEPT, HeaderValue::from_str(&EncodingType::Json.to_string()).unwrap());
415+
.insert(ACCEPT, HeaderValue::from_str(EncodingType::Json.content_type()).unwrap());
416416
let config = RequestContext {
417417
url: req_config.url.clone(),
418418
timeout_ms: req_config.timeout_ms - elapsed,

crates/pbs/src/routes/get_header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub async fn handle_get_header<S: BuilderApiState, A: BuilderApi<S>>(
7373

7474
// This won't actually fail since the string is a const
7575
let content_type_header =
76-
HeaderValue::from_str(&EncodingType::Ssz.to_string()).unwrap();
76+
HeaderValue::from_str(EncodingType::Ssz.content_type()).unwrap();
7777

7878
res.headers_mut().insert(CONSENSUS_VERSION_HEADER, consensus_version_header);
7979
res.headers_mut().insert(CONTENT_TYPE, content_type_header);

crates/pbs/src/routes/submit_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ async fn handle_submit_block_impl<S: BuilderApiState, A: BuilderApi<S>>(
110110

111111
// This won't actually fail since the string is a const
112112
let content_type_header =
113-
HeaderValue::from_str(&EncodingType::Ssz.to_string()).unwrap();
113+
HeaderValue::from_str(EncodingType::Ssz.content_type()).unwrap();
114114

115115
response
116116
.headers_mut()

0 commit comments

Comments
 (0)