From ed53a8d000c50f3c9969284d642fd15e12258772 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 3 Sep 2021 20:12:27 +0100 Subject: Default sitemap to XML --- gentoobrowse/src/search.cpp | 13 ++++++++++--- gentoobrowse/src/test.cpp | 22 +++++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/gentoobrowse/src/search.cpp b/gentoobrowse/src/search.cpp index d1241fa..52a5846 100644 --- a/gentoobrowse/src/search.cpp +++ b/gentoobrowse/src/search.cpp @@ -25,10 +25,10 @@ namespace GentooBrowse { public: sitemap(const IceSpider::Core * core) : IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/sitemap.xml"), - prx0(core->getProxy()) + prx0(core->getProxy()), + sitemaps {std::make_shared("xslt/sitemap.xslt")} { - addRouteSerializer({"application", "xml"}, - std::make_shared("xslt/sitemap.xslt")); + addRouteSerializer({"application", "xml"}, sitemaps); } void @@ -53,8 +53,15 @@ namespace GentooBrowse { request->response(this, _responseModel); } + IceSpider::ContentTypeSerializer + defaultSerializer(std::ostream & strm) const override + { + return {{"application", "xml"}, sitemaps->create(strm)}; + } + private: const Gentoo::PortagePrxPtr prx0; + StreamSerializerFactoryPtr sitemaps; }; } // namespace GentooBrowse diff --git a/gentoobrowse/src/test.cpp b/gentoobrowse/src/test.cpp index 238efb4..aa49a07 100644 --- a/gentoobrowse/src/test.cpp +++ b/gentoobrowse/src/test.cpp @@ -86,12 +86,9 @@ public: } }; -class ChromiumRequestXml : public ChromiumRequest { +class ChromiumRequestDefaultXml : public ChromiumRequest { public: - ChromiumRequestXml(const Core * c, HttpMethod m, const std::string & p) : ChromiumRequest(c, m, p) - { - hdr["Accept"] = "application/xml"; - } + using ChromiumRequest::ChromiumRequest; virtual void standardAssertions(const char *) override @@ -104,6 +101,14 @@ public: } }; +class ChromiumRequestXml : public ChromiumRequestDefaultXml { +public: + ChromiumRequestXml(const Core * c, HttpMethod m, const std::string & p) : ChromiumRequestDefaultXml(c, m, p) + { + hdr["Accept"] = "application/xml"; + } +}; + class ChromiumRequestAtom : public ChromiumRequest { public: ChromiumRequestAtom(const Core * c, HttpMethod m, const std::string & p) : ChromiumRequest(c, m, p) @@ -255,6 +260,13 @@ BOOST_AUTO_TEST_CASE(search_sitemap) request.standardAssertions(typeid(*this).name()); } +BOOST_AUTO_TEST_CASE(search_sitemap_dfl) +{ + ChromiumRequestDefaultXml request(this, HttpMethod::GET, "/sitemap.xml"); + process(&request); + request.standardAssertions(typeid(*this).name()); +} + BOOST_AUTO_TEST_CASE(home_atom) { ChromiumRequestAtom request(this, HttpMethod::GET, "/"); -- cgit v1.2.3