Skip to content

Commit f43ca1a

Browse files
committed
fix: allow arbitrary response handler only if there is no handler found, and turn it on by default in the parse_response() helper. Also, it's no longer an error to omit content-type; per the RFC, this defaults to application/octet-stream
1 parent 705ebf3 commit f43ca1a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

stackslib/src/net/http/tests.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,6 @@ fn test_parse_http_response_preamble_err() {
368368
"Unsupported HTTP content type"),
369369
("HTTP/1.1 200 OK\r\nContent-Length: foo\r\n\r\n",
370370
"Invalid Content-Length"),
371-
("HTTP/1.1 200 OK\r\nContent-Length: 123\r\n\r\n",
372-
"missing Content-Type, Content-Length"),
373371
("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n",
374372
"missing Content-Type, Content-Length"),
375373
("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 123\r\nTransfer-Encoding: chunked\r\n\r\n",

stackslib/src/net/httpcore.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,7 @@ impl StacksHttp {
13561356
"127.0.0.1:20443".parse().unwrap(),
13571357
&ConnectionOptions::default(),
13581358
);
1359+
http.allow_arbitrary_response = true;
13591360

13601361
let (preamble, message_offset) = http.read_preamble(response_buf)?;
13611362
let is_chunked = match preamble {
@@ -1498,7 +1499,9 @@ impl ProtocolFamily for StacksHttp {
14981499
num_read,
14991500
);
15001501

1501-
let parse_res = if self.allow_arbitrary_response {
1502+
let parse_res = if self.request_handler_index.is_none()
1503+
&& self.allow_arbitrary_response
1504+
{
15021505
let arbitrary_parser = RPCArbitraryResponseHandler {};
15031506
let response_payload = arbitrary_parser
15041507
.try_parse_response(http_response_preamble, &message_bytes[..])?;
@@ -1604,7 +1607,7 @@ impl ProtocolFamily for StacksHttp {
16041607
// message of known length
16051608
test_debug!("read http response payload of {} bytes", buf.len(),);
16061609

1607-
if self.allow_arbitrary_response {
1610+
if self.request_handler_index.is_none() && self.allow_arbitrary_response {
16081611
let arbitrary_parser = RPCArbitraryResponseHandler {};
16091612
let response_payload =
16101613
arbitrary_parser.try_parse_response(http_response_preamble, buf)?;

0 commit comments

Comments
 (0)