QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
21 #include <QMimeDatabase>
25 : mPathRegExp( pathRegExp )
26 , mStaticPathSuffix( staticPathSuffix )
33 const QRegularExpressionMatch match {
path().match( context.
request()->
url().path( ) ) };
34 if ( ! match.hasMatch() )
39 const QString staticFilePath { match.captured( QStringLiteral(
"staticFilePath" ) ) };
42 if ( ! mStaticPathSuffix.isEmpty() )
44 filePath +=
'/' + mStaticPathSuffix;
46 filePath +=
'/' + staticFilePath;
47 if ( ! QFile::exists( filePath ) )
54 if ( ! f.open( QIODevice::ReadOnly ) )
59 const qint64 size { f.size() };
60 const QByteArray content { f.readAll() };
61 const QMimeType mimeType { QMimeDatabase().mimeTypeForFile( filePath )};
62 context.
response()->
setHeader( QStringLiteral(
"Content-Type" ), mimeType.name() );
63 context.
response()->
setHeader( QStringLiteral(
"Content-Length" ), QString::number( size ) );
void handleRequest(const QgsServerApiContext &context) const override
Handles the request within its context.
The QgsServerApiContext class encapsulates the resources for a particular client request: the request...
virtual const QString staticPath(const QgsServerApiContext &context) const
Returns the absolute path to the base directory where static resources for this handler are stored in...
Not found error API exception.
Internal server error API exception.
void setContentTypes(const QList< QgsServerOgcApi::ContentType > &contentTypes)
Set the content types to contentTypes.
virtual void write(const QString &data)
Write string This is a convenient method that will write directly to the underlying I/O device.
QgsServerResponse * response() const
Returns the server response object.
QRegularExpression path() const override
URL pattern for this handler, named capture group are automatically extracted and returned by values(...
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
const QgsServerRequest * request() const
Returns the server request object.
QgsServerStaticHandler(const QString &pathRegExp=QStringLiteral("/static/(?<staticFilePath>.*)$"), const QString &staticPathSuffix=QString())
Creates QgsServerStaticHandler.
virtual void setHeader(const QString &key, const QString &value)=0
Set Header entry Add Header entry to the response Note that it is usually an error to set Header afte...