Skip to content

Commit

Permalink
fix(Serve): Return formats like Markdown as plain text
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Oct 10, 2021
1 parent 41ab4b0 commit d5355a6
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions rust/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,10 +713,23 @@ async fn get_handler(
let mime = mime_guess::from_ext(&format).first_or_octet_stream();

let mut response = warp::reply::Response::new(content.into());
response.headers_mut().insert(
"content-type",
warp::http::header::HeaderValue::from_str(mime.as_ref()).unwrap(),
);
match format.as_str() {
"html" | "json" => {
response.headers_mut().insert(
"content-type",
warp::http::header::HeaderValue::from_str(mime.as_ref()).unwrap(),
);
}
_ => {
// Temporary serve other content as plain text to avoid browser download
// In the future, this will be replace with a code editing view.
response.headers_mut().insert(
"content-type",
warp::http::header::HeaderValue::from_str("text/plain; charset=utf-8")
.unwrap(),
);
}
}
Ok(response)
}
Err(error) => error_response(
Expand Down Expand Up @@ -757,7 +770,7 @@ pub fn rewrite_html(body: &str, mode: &str, theme: &str, cwd: &Path, document: &
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="/~static/web/browser/{mode}.js"></script>
<script src="/~static/web/{mode}.js"></script>
<script>
const startup = stencilaWebClient.main("{url}", "{client}", "{project}", "{snapshot}", "{document}");
startup().catch((err) => console.error('Error during startup', err))
Expand Down

0 comments on commit d5355a6

Please sign in to comment.