Skip to content

Commit a52b531

Browse files
committed
address review comments
1 parent 86552c0 commit a52b531

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

crates/common/src/wire.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,15 @@ mod test {
549549
assert!(result.is_err());
550550
}
551551

552+
/// Test rejecting an unknown Accept: / type
553+
#[test]
554+
fn test_invalid_accept_header_type_slash() {
555+
let mut headers = HeaderMap::new();
556+
headers.append(ACCEPT, HeaderValue::from_str("/").unwrap());
557+
let result = get_accept_types(&headers);
558+
assert!(result.is_err());
559+
}
560+
552561
/// Test accepting one header with multiple values
553562
#[test]
554563
fn test_accept_header_invalid_parse() {
@@ -834,6 +843,13 @@ mod test {
834843
assert_eq!(get_content_type(&headers), EncodingType::Json);
835844
}
836845

846+
#[test]
847+
fn test_content_type_invalid_defaults_to_json() {
848+
let mut headers = HeaderMap::new();
849+
headers.append(CONTENT_TYPE, HeaderValue::from_str("/").unwrap());
850+
assert_eq!(get_content_type(&headers), EncodingType::Json);
851+
}
852+
837853
// ── get_consensus_version_header ─────────────────────────────────────────
838854

839855
#[test]

crates/pbs/src/mev_boost/get_header.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use cb_common::{
2121
types::{BlsPublicKey, BlsPublicKeyBytes, BlsSignature, Chain},
2222
utils::{ms_into_slot, timestamp_of_slot_start_sec, utcnow_ms},
2323
wire::{
24-
AcceptedEncodingsError, EncodingType, OUTBOUND_ACCEPT, get_user_agent_with_version,
24+
EncodingType, OUTBOUND_ACCEPT, get_user_agent_with_version,
2525
parse_response_encoding_and_fork, safe_read_http_response,
2626
},
2727
};
@@ -152,14 +152,7 @@ pub async fn get_header<S: BuilderApiState>(
152152
// Create the Accept headers for requests
153153
// Use the documented, deterministic preference:
154154
// SSZ first (wire-efficient), JSON fallback.
155-
send_headers.insert(
156-
ACCEPT,
157-
HeaderValue::from_str(OUTBOUND_ACCEPT).map_err(|e| {
158-
AcceptedEncodingsError::InvalidEncoding {
159-
error_msg: (format!("invalid accept header: {e}")).to_string(),
160-
}
161-
})?,
162-
);
155+
send_headers.insert(ACCEPT, HeaderValue::from_static(OUTBOUND_ACCEPT));
163156

164157
// Send requests to all relays concurrently
165158
let slot = params.slot as i64;
@@ -506,7 +499,7 @@ async fn send_get_header_impl(
506499
let start_request = Instant::now();
507500
let res = match relay
508501
.client
509-
.get(url.as_ref())
502+
.get(url)
510503
.timeout(Duration::from_millis(timeout_left_ms))
511504
.headers(headers)
512505
.send()

0 commit comments

Comments
 (0)