parse XML documents, save non-HTML and non-XML targets unparsed

pull/322/head
Sunshine 2 years ago
parent 7c61b462dd
commit 8fc0fc155f

@ -175,12 +175,21 @@ fn main() {
{ {
match retrieve_asset(&mut cache, &client, &target_url, &target_url, &options, 0) { match retrieve_asset(&mut cache, &client, &target_url, &target_url, &options, 0) {
Ok((retrieved_data, final_url, media_type, charset)) => { Ok((retrieved_data, final_url, media_type, charset)) => {
// Make sure the media type is text/html // Provide output as text without processing it, the way browsers do
if !media_type.eq_ignore_ascii_case("text/html") { if !media_type.eq_ignore_ascii_case("text/html")
if !options.silent { && !media_type.eq_ignore_ascii_case("application/xhtml+xml")
eprintln!("Unsupported document media type"); {
} // Define output
process::exit(1); let mut output =
Output::new(&options.output).expect("Could not prepare output");
// Write retrieved data into STDOUT or file
output
.write(&retrieved_data)
.expect("Could not write output");
// Nothing else to do past this point
process::exit(0);
} }
if options if options
@ -324,6 +333,6 @@ fn main() {
// Define output // Define output
let mut output = Output::new(&options.output).expect("Could not prepare output"); let mut output = Output::new(&options.output).expect("Could not prepare output");
// Write result into stdout or file // Write result into STDOUT or file
output.write(&result).expect("Could not write HTML output"); output.write(&result).expect("Could not write output");
} }

Loading…
Cancel
Save