From cb497a0ccae3f90122c6c8d6d99addded11cd501 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 11 May 2021 23:58:10 +0200 Subject: feat(atward): Serve OpenSearch XML file to support Firefox Firefox users can not easily add search engines to the browser unless the page serves an OpenSearch description. This CL adds said description according to the documentation: https://developer.mozilla.org/en-US/docs/Web/OpenSearch Change-Id: I358c5940304f4abd9e45dd72a64e46d3ce44b3e3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/3105 Tested-by: BuildkiteCI Reviewed-by: cynthia --- web/atward/src/index.html | 1 + web/atward/src/main.rs | 11 +++++++++++ web/atward/src/opensearch.xml | 8 ++++++++ 3 files changed, 20 insertions(+) create mode 100644 web/atward/src/opensearch.xml (limited to 'web/atward') diff --git a/web/atward/src/index.html b/web/atward/src/index.html index c9a7c494e9..286bc6e546 100644 --- a/web/atward/src/index.html +++ b/web/atward/src/index.html @@ -4,6 +4,7 @@ + TVL Search
diff --git a/web/atward/src/main.rs b/web/atward/src/main.rs index 44ab4d29c2..04beb02cd5 100644 --- a/web/atward/src/main.rs +++ b/web/atward/src/main.rs @@ -113,6 +113,13 @@ fn dispatch(handlers: &[Handler], query: &Query) -> Option { None } +/// Return the opensearch.xml file which is required for adding atward +/// as a search engine in Firefox. +fn opensearch() -> Response { + Response::text(include_str!("opensearch.xml")) + .with_unique_header("Content-Type", "application/opensearchdescription+xml") +} + /// Render the atward index page which gives users some information /// about how to use the service. fn index() -> Response { @@ -133,6 +140,10 @@ fn main() { rouille::start_server(&address, move |request| { rouille::log(&request, std::io::stderr(), || { + if request.url() == "/opensearch.xml" { + return opensearch(); + } + let query = match Query::from_request(&request) { Some(q) => q, None => return index(), diff --git a/web/atward/src/opensearch.xml b/web/atward/src/opensearch.xml new file mode 100644 index 0000000000..6033987f5b --- /dev/null +++ b/web/atward/src/opensearch.xml @@ -0,0 +1,8 @@ + + TVL + The Virus Lounge Search + UTF-8 + + + + -- cgit 1.4.1