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 )
109 else if ( strcmp( me,
"PATCH" ) == 0 )
125 const char *accept = getenv(
"HTTP_ACCEPT" );
128 setHeader( QStringLiteral(
"Accept" ), accept );
135 printRequestInfos( url );
145 void QgsFcgiServerRequest::readData()
148 const char *lengthstr = getenv(
"CONTENT_LENGTH" );
151 bool success =
false;
152 int length = QString( lengthstr ).toInt( &success );
157 const char *request_body = getenv(
"REQUEST_BODY" );
158 if ( success && request_body )
160 QString body( request_body );
161 body.truncate( length );
162 mData.append( body.toUtf8() );
166 qDebug() <<
"fcgi: reading " << lengthstr <<
" bytes from " << ( request_body ?
"REQUEST_BODY" :
"stdin" );
171 for (
int i = 0; i < length; ++i )
173 mData.append( getchar() );
189 void QgsFcgiServerRequest::printRequestInfos(
const QUrl &
url )
193 const QStringList envVars
195 QStringLiteral(
"SERVER_NAME" ),
196 QStringLiteral(
"REQUEST_URI" ),
197 QStringLiteral(
"SCRIPT_NAME" ),
198 QStringLiteral(
"HTTPS" ),
199 QStringLiteral(
"REMOTE_ADDR" ),
200 QStringLiteral(
"REMOTE_HOST" ),
201 QStringLiteral(
"SERVER_PORT" ),
202 QStringLiteral(
"QUERY_STRING" ),
203 QStringLiteral(
"REMOTE_USER" ),
204 QStringLiteral(
"REMOTE_IDENT" ),
205 QStringLiteral(
"CONTENT_TYPE" ),
206 QStringLiteral(
"REQUEST_METHOD" ),
207 QStringLiteral(
"AUTH_TYPE" ),
208 QStringLiteral(
"HTTP_ACCEPT" ),
209 QStringLiteral(
"HTTP_USER_AGENT" ),
210 QStringLiteral(
"HTTP_PROXY" ),
211 QStringLiteral(
"NO_PROXY" ),
212 QStringLiteral(
"HTTP_AUTHORIZATION" ),
213 QStringLiteral(
"QGIS_PROJECT_FILE" )
220 for (
const auto &envVar : envVars )
222 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).
void setHeader(const QString &name, const QString &value)
Set an header.
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)