Skip to content

Commit 064abd1

Browse files
committed
[rest] add a more verbose error message for invalid header counts
1 parent 83b8f3a commit 064abd1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/rest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static bool rest_headers(const std::any& context,
195195

196196
const auto parsed_count{ToIntegral<size_t>(path[0])};
197197
if (!parsed_count.has_value() || *parsed_count < 1 || *parsed_count > MAX_REST_HEADERS_RESULTS) {
198-
return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Header count out of acceptable range (1-%u): %s", MAX_REST_HEADERS_RESULTS, path[0]));
198+
return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Header count is invalid or out of acceptable range (1-%u): %s", MAX_REST_HEADERS_RESULTS, path[0]));
199199
}
200200

201201
std::string hashStr = path[1];
@@ -371,7 +371,7 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const
371371

372372
const auto parsed_count{ToIntegral<size_t>(uri_parts[1])};
373373
if (!parsed_count.has_value() || *parsed_count < 1 || *parsed_count > MAX_REST_HEADERS_RESULTS) {
374-
return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Header count out of acceptable range (1-%u): %s", MAX_REST_HEADERS_RESULTS, uri_parts[1]));
374+
return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Header count is invalid or out of acceptable range (1-%u): %s", MAX_REST_HEADERS_RESULTS, uri_parts[1]));
375375
}
376376

377377
std::vector<const CBlockIndex*> headers;

test/functional/interface_rest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def run_test(self):
279279
# Test number parsing
280280
for num in ['5a', '-5', '0', '2001', '99999999999999999999999999999999999']:
281281
assert_equal(
282-
bytes(f'Header count out of acceptable range (1-2000): {num}\r\n', 'ascii'),
282+
bytes(f'Header count is invalid or out of acceptable range (1-2000): {num}\r\n', 'ascii'),
283283
self.test_rest_request(f"/headers/{num}/{bb_hash}", ret_type=RetType.BYTES, status=400),
284284
)
285285

0 commit comments

Comments
 (0)