From 78bd53e64061fba665027967637dba53a168ceaa Mon Sep 17 00:00:00 2001 From: Magnus Hoff Date: Wed, 1 Nov 2017 13:15:42 +0100 Subject: [PATCH] Machine readable branding. Include project name and version in Server header and generator meta tag --- src/site.rs | 19 ++++++++++++------- templates/layout.html | 1 + 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/site.rs b/src/site.rs index d0961a7..048d4ed 100644 --- a/src/site.rs +++ b/src/site.rs @@ -4,7 +4,7 @@ use std::fmt; use futures::{self, Future}; -use hyper::header::{Accept, ContentType}; +use hyper::header::{Accept, ContentType, Server}; use hyper::mime; use hyper::server::*; use hyper; @@ -28,13 +28,11 @@ pub struct Layout<'a, T: 'a + fmt::Display> { } impl<'a, T: 'a + fmt::Display> Layout<'a, T> { - pub fn style_css_checksum(&self) -> &str { - StyleCss::checksum() - } + pub fn style_css_checksum(&self) -> &str { StyleCss::checksum() } + pub fn search_js_checksum(&self) -> &str { SearchJs::checksum() } - pub fn search_js_checksum(&self) -> &str { - SearchJs::checksum() - } + pub fn pkg_name(&self) -> &str { env!("CARGO_PKG_NAME") } + pub fn pkg_version(&self) -> &str { env!("CARGO_PKG_VERSION") } } #[derive(BartDisplay)] @@ -128,6 +126,13 @@ impl Service for Site { None => Box::new(futures::finished(Self::not_found(base.as_ref().map(|x| &**x)))) }) .or_else(move |err| Ok(Self::internal_server_error(base2.as_ref().map(|x| &**x), err))) + .map(|response| response + .with_header(Server::new(concat!( + env!("CARGO_PKG_NAME"), + "/", + env!("CARGO_PKG_VERSION") + ))) + ) ) } } diff --git a/templates/layout.html b/templates/layout.html index 0fc6f23..a4874e2 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -6,6 +6,7 @@ {{#base}}{{/base}} + {{>search_input.html}}