24 #include <fcgi_stdio.h> 32 QString uri = getenv(
"REQUEST_URI" );
36 uri = getenv(
"SCRIPT_NAME" );
42 if ( url.host().isEmpty() )
44 url.setHost( getenv(
"SERVER_NAME" ) );
48 if ( url.port( -1 ) == -1 )
50 QString portString = getenv(
"SERVER_PORT" );
51 if ( !portString.isEmpty() )
54 int portNumber = portString.toInt( &portOk );
55 if ( portOk && portNumber != 80 )
57 url.setPort( portNumber );
63 if ( url.scheme().isEmpty() )
65 QString( getenv(
"HTTPS" ) ).compare( QLatin1String(
"on" ), Qt::CaseInsensitive ) == 0
66 ? url.setScheme( QStringLiteral(
"https" ) )
67 : url.setScheme( QStringLiteral(
"http" ) );
76 const char *qs = getenv(
"QUERY_STRING" );
83 qDebug() <<
"fcgi query string: " << url.query();
89 const char *me = getenv(
"REQUEST_METHOD" );
93 if ( strcmp( me,
"POST" ) == 0 )
97 else if ( strcmp( me,
"PUT" ) == 0 )
101 else if ( strcmp( me,
"DELETE" ) == 0 )
105 else if ( strcmp( me,
"HEAD" ) == 0 )
134 void QgsFcgiServerRequest::readData()
137 const char *lengthstr = getenv(
"CONTENT_LENGTH" );
140 bool success =
false;
141 int length = QString( lengthstr ).toInt( &success );
146 const char *request_body = getenv(
"REQUEST_BODY" );
147 if ( success && request_body )
149 QString body( request_body );
150 body.truncate( length );
151 mData.append( body.toUtf8() );
155 qDebug() <<
"fcgi: reading " << lengthstr <<
" bytes from " << ( request_body ?
"REQUEST_BODY" :
"stdin" );
160 for (
int i = 0; i < length; ++i )
162 mData.append( getchar() );
178 void QgsFcgiServerRequest::printRequestInfos()
182 const QStringList envVars
184 QStringLiteral(
"SERVER_NAME" ),
185 QStringLiteral(
"REQUEST_URI" ),
186 QStringLiteral(
"REMOTE_ADDR" ),
187 QStringLiteral(
"REMOTE_HOST" ),
188 QStringLiteral(
"REMOTE_USER" ),
189 QStringLiteral(
"REMOTE_IDENT" ),
190 QStringLiteral(
"CONTENT_TYPE" ),
191 QStringLiteral(
"AUTH_TYPE" ),
192 QStringLiteral(
"HTTP_USER_AGENT" ),
193 QStringLiteral(
"HTTP_PROXY" ),
194 QStringLiteral(
"NO_PROXY" ),
195 QStringLiteral(
"HTTP_AUTHORIZATION" )
198 for (
const auto &envVar : envVars )
200 if ( getenv( envVar.toStdString().c_str() ) )
void setMethod(QgsServerRequest::Method method)
Set the request method.
Qgis::MessageLevel logLevel() const
Gets the current log level.
void setUrl(const QUrl &url)
Set the request url.
Method
HTTP Method (or equivalent) used for the request.
MessageLevel
Level for messages This will be used both for message log and message bar in application.
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).
static QgsServerLogger * instance()
Gets the singleton instance.
QByteArray data() const override
Returns post/put data Check for QByteArray::isNull() to check if data is available.
QgsServerRequest::Method method() const
void setOriginalUrl(const QUrl &url)
Set the request original url (the request url as seen by the web server)