feat(error): add Error::is_parse_too_large and Error::is_parse_status methods (#2538)

The discussion in #2462 opened up some larger questions about more comprehensive approaches to the
error API, with the agreement that additional methods would be desirable in the short term. These
methods address an immediate need of our customers, so I would like to get them in first before we
flesh out a future solution.

One potentially controversial choice here is to still return `true` from `is_parse_error()` for
these variants. I hope the naming of the methods make it clear that the new predicates are
refinements of the existing one, but I didn't want to change the behavior of `is_parse_error()`
which would require a major version bump.
This commit is contained in:
Adam C. Foltzer
2021-05-12 18:30:28 -07:00
committed by GitHub
parent b9916c4101
commit 960a69a587
2 changed files with 88 additions and 0 deletions

View File

@@ -907,6 +907,83 @@ test! {
}
test! {
name: client_error_parse_too_large,
server:
expected: "\
GET /err HTTP/1.1\r\n\
host: {addr}\r\n\
\r\n\
",
reply: {
let long_header = std::iter::repeat("A").take(500_000).collect::<String>();
format!("\
HTTP/1.1 200 OK\r\n\
{}: {}\r\n\
\r\n\
",
long_header,
long_header,
)
},
client:
request: {
method: GET,
url: "http://{addr}/err",
},
// should get a Parse(TooLarge) error
error: |err| err.is_parse() && err.is_parse_too_large(),
}
test! {
name: client_error_parse_status_out_of_range,
server:
expected: "\
GET /err HTTP/1.1\r\n\
host: {addr}\r\n\
\r\n\
",
reply: "\
HTTP/1.1 001 OK\r\n\
\r\n\
",
client:
request: {
method: GET,
url: "http://{addr}/err",
},
// should get a Parse(Status) error
error: |err| err.is_parse() && err.is_parse_status(),
}
test! {
name: client_error_parse_status_syntactically_invalid,
server:
expected: "\
GET /err HTTP/1.1\r\n\
host: {addr}\r\n\
\r\n\
",
reply: "\
HTTP/1.1 1 OK\r\n\
\r\n\
",
client:
request: {
method: GET,
url: "http://{addr}/err",
},
// should get a Parse(Status) error
error: |err| err.is_parse() && err.is_parse_status(),
}
test! {
name: client_100_continue,