mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Fallback to extension-based content type detection when parsing Content-Type
header fails (#13610)
# Description Previously when nushell failed to parse the content type header, it would emit an error instead of returning the response. Now it will fall back to `text/plain` (which, in turn, will trigger type detection based on file extension). May fix (potentially) nushell/nushell#11927 Refs: https://discord.com/channels/601130461678272522/614593951969574961/1272895236489613366 Supercedes: #13609 # User-Facing Changes It's now possible to fetch content even if the server returns an invalid content type header. Users may need to parse the response manually, but it's still better than not getting the response at all. # Tests + Formatting Added a test for the new behaviour. # After Submitting
This commit is contained in:
@ -273,3 +273,46 @@ fn http_get_self_signed_override() {
|
||||
let actual = nu!("http get --insecure https://self-signed.badssl.com/");
|
||||
assert!(actual.out.contains("<html>"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn http_get_with_invalid_mime_type() {
|
||||
let mut server = Server::new();
|
||||
|
||||
let _mock = server
|
||||
.mock("GET", "/foo.nuon")
|
||||
.with_status(200)
|
||||
// `what&ever` is not a parseable MIME type
|
||||
.with_header("content-type", "what&ever")
|
||||
.with_body("[1 2 3]")
|
||||
.create();
|
||||
|
||||
// but `from nuon` is a known command in nu, so we take `foo.{ext}` and pass it to `from {ext}`
|
||||
let actual = nu!(pipeline(
|
||||
format!(
|
||||
r#"http get {url}/foo.nuon | to json --raw"#,
|
||||
url = server.url()
|
||||
)
|
||||
.as_str()
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "[1,2,3]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn http_get_with_unknown_mime_type() {
|
||||
let mut server = Server::new();
|
||||
let _mock = server
|
||||
.mock("GET", "/foo")
|
||||
.with_status(200)
|
||||
// `application/nuon` is not an IANA-registered MIME type
|
||||
.with_header("content-type", "application/nuon")
|
||||
.with_body("[1 2 3]")
|
||||
.create();
|
||||
|
||||
// but `from nuon` is a known command in nu, so we take `{garbage}/{whatever}` and pass it to `from {whatever}`
|
||||
let actual = nu!(pipeline(
|
||||
format!(r#"http get {url}/foo | to json --raw"#, url = server.url()).as_str()
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "[1,2,3]");
|
||||
}
|
||||
|
Reference in New Issue
Block a user