25#include <fcgi_stdio.h> 
   31  QString uri = getenv( 
"REQUEST_URI" );
 
   35    uri = getenv( 
"SCRIPT_NAME" );
 
   44  const QString qs = getenv( 
"QUERY_STRING" );
 
   45  const QString questionMark = qs.isEmpty() ? QString() : QChar( 
'?' );
 
   46  const QString extraPath = QStringLiteral( 
"%1%2%3" ).arg( getenv( 
"PATH_INFO" ) ).arg( questionMark ).arg( qs );
 
   49  if ( uri.endsWith( extraPath ) )
 
   51    baseUrl.setUrl( uri.left( uri.length() - extraPath.length() ) );
 
   69  qDebug() << 
"fcgi query string: " << 
url.query();
 
   75  const char *me = getenv( 
"REQUEST_METHOD" );
 
   79    if ( strcmp( me, 
"POST" ) == 0 )
 
   83    else if ( strcmp( me, 
"PUT" ) == 0 )
 
   87    else if ( strcmp( me, 
"DELETE" ) == 0 )
 
   91    else if ( strcmp( me, 
"HEAD" ) == 0 )
 
   95    else if ( strcmp( me, 
"PATCH" ) == 0 )
 
  111  for ( 
const auto &headerKey : qgsEnumMap<QgsServerRequest::RequestHeader>() )
 
  116                                 .replace( QLatin1Char( 
' ' ), QLatin1Char( 
'-' ) );
 
  117    const char *result = getenv( QStringLiteral( 
"HTTP_%1" ).arg( headerKey ).toStdString().c_str() );
 
  118    if ( result && strlen( result ) > 0 )
 
  128    printRequestInfos( 
url );
 
 
  132void QgsFcgiServerRequest::fillUrl( QUrl &url )
 const 
  135  if ( 
url.host().isEmpty() )
 
  137    url.setHost( getenv( 
"SERVER_NAME" ) );
 
  141  if ( 
url.port( -1 ) == -1 )
 
  143    const QString portString = getenv( 
"SERVER_PORT" );
 
  144    if ( !portString.isEmpty() )
 
  147      const int portNumber = portString.toInt( &portOk );
 
  148      if ( portOk && portNumber != 80 )
 
  150        url.setPort( portNumber );
 
  156  if ( 
url.scheme().isEmpty() )
 
  158    QString( getenv( 
"HTTPS" ) ).compare( QLatin1String( 
"on" ), Qt::CaseInsensitive ) == 0
 
  159      ? 
url.setScheme( QStringLiteral( 
"https" ) )
 
  160      : 
url.setScheme( QStringLiteral( 
"http" ) );
 
  170void QgsFcgiServerRequest::readData()
 
  173  const char *lengthstr = getenv( 
"CONTENT_LENGTH" );
 
  176    bool success = 
false;
 
  177    const int length = QString( lengthstr ).toInt( &success );
 
  178    if ( !success || length < 0 )
 
  189      const char *requestBody = getenv( 
"REQUEST_BODY" );
 
  192      qDebug() << 
"fcgi: reading " << lengthstr << 
" bytes from " << ( requestBody ? 
"REQUEST_BODY" : 
"stdin" );
 
  197        const size_t requestBodyLength = strlen( requestBody );
 
  198        const int actualLength = 
static_cast<int>( std::min<size_t>( length, requestBodyLength ) );
 
  199        if ( 
static_cast<size_t>( actualLength ) < requestBodyLength )
 
  204        mData = QByteArray::fromRawData( requestBody, actualLength );
 
  208        mData.resize( length );
 
  209        const int actualLength = 
static_cast<int>( fread( mData.data(), 1, length, stdin ) );
 
  210        if ( actualLength < length )
 
  212          mData.resize( actualLength );
 
  225void QgsFcgiServerRequest::printRequestInfos( 
const QUrl &url )
 const 
  229  const QStringList envVars {
 
  230    QStringLiteral( 
"SERVER_NAME" ),
 
  231    QStringLiteral( 
"REQUEST_URI" ),
 
  232    QStringLiteral( 
"SCRIPT_NAME" ),
 
  233    QStringLiteral( 
"PATH_INFO" ),
 
  234    QStringLiteral( 
"HTTPS" ),
 
  235    QStringLiteral( 
"REMOTE_ADDR" ),
 
  236    QStringLiteral( 
"REMOTE_HOST" ),
 
  237    QStringLiteral( 
"SERVER_PORT" ),
 
  238    QStringLiteral( 
"QUERY_STRING" ),
 
  239    QStringLiteral( 
"REMOTE_USER" ),
 
  240    QStringLiteral( 
"REMOTE_IDENT" ),
 
  241    QStringLiteral( 
"CONTENT_TYPE" ),
 
  242    QStringLiteral( 
"REQUEST_METHOD" ),
 
  243    QStringLiteral( 
"AUTH_TYPE" ),
 
  244    QStringLiteral( 
"HTTP_PROXY" ),
 
  245    QStringLiteral( 
"NO_PROXY" ),
 
  246    QStringLiteral( 
"QGIS_PROJECT_FILE" ),
 
  247    QStringLiteral( 
"QGIS_SERVER_IGNORE_BAD_LAYERS" ),
 
  248    QStringLiteral( 
"QGIS_SERVER_SERVICE_URL" ),
 
  249    QStringLiteral( 
"QGIS_SERVER_WMS_SERVICE_URL" ),
 
  250    QStringLiteral( 
"QGIS_SERVER_WFS_SERVICE_URL" ),
 
  251    QStringLiteral( 
"QGIS_SERVER_WMTS_SERVICE_URL" ),
 
  252    QStringLiteral( 
"QGIS_SERVER_WCS_SERVICE_URL" ),
 
  253    QStringLiteral( 
"SERVER_PROTOCOL" )
 
  260  for ( 
const auto &envVar : envVars )
 
  262    if ( getenv( envVar.toStdString().c_str() ) )
 
  268  qDebug() << 
"Headers:";
 
  269  qDebug() << 
"------------------------------------------------";
 
  270  const QMap<QString, QString> &hdrs = 
headers();
 
  271  for ( 
auto it = hdrs.constBegin(); it != hdrs.constEnd(); it++ )
 
  273    qDebug() << it.key() << 
": " << it.value();
 
  284  if ( result.isEmpty() )
 
  286    result = qgetenv( QStringLiteral( 
"HTTP_%1" ).arg( name.toUpper().replace( QLatin1Char( 
'-' ), QLatin1Char( 
'_' ) ) ).toStdString().c_str() );
 
 
MessageLevel
Level for messages This will be used both for message log and message bar in application.
 
@ Critical
Critical/error message.
 
@ Info
Information message.
 
@ TitleCase
Simple title case conversion - does not fully grammatically parse the text and uses simple rules only...
 
QString header(const QString &name) const override
Returns the header value.
 
QByteArray data() const override
Returns post/put data Check for QByteArray::isNull() to check if data is available.
 
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
 
static QgsServerLogger * instance()
Gets the singleton instance.
 
Qgis::MessageLevel logLevel() const
Gets the current log level.
 
void setOriginalUrl(const QUrl &url)
Set the request original url (the request url as seen by the web server)
 
Method
HTTP Method (or equivalent) used for the request.
 
virtual QString header(const QString &name) const
Returns the header value.
 
virtual void setUrl(const QUrl &url)
Set the request url.
 
QUrl url() const
Returns the request URL as seen by QGIS server.
 
QMap< QString, QString > headers() const
Returns the header map.
 
QUrl baseUrl() const
Returns the base URL of QGIS server.
 
QgsServerRequest::Method method() const
Returns the request method.
 
void setMethod(QgsServerRequest::Method method)
Set the request method.
 
void setBaseUrl(const QUrl &url)
Set the base URL of QGIS server.
 
void setHeader(const QString &name, const QString &value)
Set an header.
 
static QString capitalize(const QString &string, Qgis::Capitalization capitalization)
Converts a string by applying capitalization rules to the string.