26 QMap<QgsServerOgcApi::ContentType, QStringList> QgsServerOgcApi::sContentTypeMime = [ ]() -> QMap<QgsServerOgcApi::ContentType, QStringList>
28 QMap<QgsServerOgcApi::ContentType, QStringList> map;
29 map[QgsServerOgcApi::ContentType::JSON] = QStringList { QStringLiteral(
"application/json" ) };
30 map[QgsServerOgcApi::ContentType::GEOJSON] = QStringList {
31 QStringLiteral(
"application/geo+json" ),
32 QStringLiteral(
"application/vnd.geo+json" ),
33 QStringLiteral(
"application/geojson" )
35 map[QgsServerOgcApi::ContentType::HTML] = QStringList { QStringLiteral(
"text/html" ) };
36 map[QgsServerOgcApi::ContentType::OPENAPI3] = QStringList { QStringLiteral(
"application/vnd.oai.openapi+json;version=3.0" ) };
37 map[QgsServerOgcApi::ContentType::XML] = QStringList { QStringLiteral(
"application/xml" ) };
41 QHash<QgsServerOgcApi::ContentType, QList<QgsServerOgcApi::ContentType>> QgsServerOgcApi::sContentTypeAliases = [ ]() -> QHash<ContentType, QList<ContentType>>
43 QHash<QgsServerOgcApi::ContentType, QList<QgsServerOgcApi::ContentType>> map;
44 map[ContentType::JSON] = { QgsServerOgcApi::ContentType::GEOJSON, QgsServerOgcApi::ContentType::OPENAPI3 };
51 mRootPath( rootPath ),
53 mDescription( description ),
66 std::shared_ptr<QgsServerOgcApiHandler> hp( handler );
67 mHandlers.emplace_back( std::move( hp ) );
73 QUrl u { url.adjusted( QUrl::StripTrailingSlash | QUrl::NormalizePathSegments ) };
74 if ( u.path().contains( QLatin1String(
"//" ) ) )
76 u.setPath( u.path().replace( QLatin1String(
"//" ), QChar(
'/' ) ) );
86 auto hasMatch {
false };
87 for (
const auto &h : mHandlers )
90 if ( h->path().match( path ).hasMatch() )
98 h->handleRequest( context );
100 catch ( json::exception &ex )
116 return sContentTypeMime;
121 return sContentTypeAliases;
126 static QMetaEnum metaEnum = QMetaEnum::fromType<QgsServerOgcApi::Rel>();
127 std::string val { metaEnum.valueToKey( rel ) };
128 std::replace( val.begin(), val.end(),
'_',
'-' );
134 static QMetaEnum metaEnum = QMetaEnum::fromType<ContentType>();
135 QString result { metaEnum.valueToKey( ct ) };
136 return result.replace(
'_',
'-' );
141 static QMetaEnum metaEnum = QMetaEnum::fromType<ContentType>();
142 return metaEnum.valueToKey( ct );
152 const QString exts = QString::fromStdString( extension );
157 const auto constValues = it.value();
158 for (
const auto &value : constValues )
160 if ( value.contains( exts, Qt::CaseSensitivity::CaseInsensitive ) )
167 QgsMessageLog::logMessage( QStringLiteral(
"Content type for extension %1 not found! Returning default (JSON)" ).arg( exts ),
168 QStringLiteral(
"Server" ),
170 return QgsServerOgcApi::ContentType::JSON;
175 if ( ! sContentTypeMime.contains( contentType ) )
179 return sContentTypeMime.value( contentType ).first().toStdString();