From 1273570e01f91113df540b00bd39dbcf9441c31a Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Tue, 25 Apr 2023 12:15:28 +0400 Subject: [PATCH] Deduplication of OPDS MIME type strings --- src/server/internalServer_catalog_v2.cpp | 28 +++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/server/internalServer_catalog_v2.cpp b/src/server/internalServer_catalog_v2.cpp index c0cb69ece..4a281d225 100644 --- a/src/server/internalServer_catalog_v2.cpp +++ b/src/server/internalServer_catalog_v2.cpp @@ -33,6 +33,24 @@ namespace kiwix { +namespace +{ + +enum OPDSResponseKind +{ + OPDS_ENTRY, + OPDS_NAVIGATION_FEED, + OPDS_ACQUISITION_FEED +}; + +const std::string opdsMimeType[] = { + "application/atom+xml;type=entry;profile=opds-catalog", + "application/atom+xml;profile=opds-catalog;kind=navigation", + "application/atom+xml;profile=opds-catalog;kind=acquisition" +}; + +} // unnamed namespace + std::unique_ptr InternalServer::handle_catalog_v2(const RequestContext& request) { if (m_verbose.load()) { @@ -90,7 +108,7 @@ std::unique_ptr InternalServer::handle_catalog_v2_root(const RequestCo {"category_list_feed_id", gen_uuid(libraryId + "/categories")}, {"language_list_feed_id", gen_uuid(libraryId + "/languages")} }, - "application/atom+xml;profile=opds-catalog;kind=navigation" + opdsMimeType[OPDS_NAVIGATION_FEED] ); } @@ -104,7 +122,7 @@ std::unique_ptr InternalServer::handle_catalog_v2_entries(const Reques return ContentResponse::build( *this, opdsFeed, - "application/atom+xml;profile=opds-catalog;kind=acquisition" + opdsMimeType[OPDS_ACQUISITION_FEED] ); } @@ -124,7 +142,7 @@ std::unique_ptr InternalServer::handle_catalog_v2_complete_entry(const return ContentResponse::build( *this, opdsFeed, - "application/atom+xml;type=entry;profile=opds-catalog" + opdsMimeType[OPDS_ENTRY] ); } @@ -136,7 +154,7 @@ std::unique_ptr InternalServer::handle_catalog_v2_categories(const Req return ContentResponse::build( *this, opdsDumper.categoriesOPDSFeed(), - "application/atom+xml;profile=opds-catalog;kind=navigation" + opdsMimeType[OPDS_NAVIGATION_FEED] ); } @@ -148,7 +166,7 @@ std::unique_ptr InternalServer::handle_catalog_v2_languages(const Requ return ContentResponse::build( *this, opdsDumper.languagesOPDSFeed(), - "application/atom+xml;profile=opds-catalog;kind=navigation" + opdsMimeType[OPDS_NAVIGATION_FEED] ); }