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 )
121 const char *accept = getenv(
"HTTP_ACCEPT" );
124 setHeader( QStringLiteral(
"Accept" ), accept );
131 printRequestInfos( url );
141 void QgsFcgiServerRequest::readData()
144 const char *lengthstr = getenv(
"CONTENT_LENGTH" );
147 bool success =
false;
148 int length = QString( lengthstr ).toInt( &success );
153 const char *request_body = getenv(
"REQUEST_BODY" );
154 if ( success && request_body )
156 QString body( request_body );
157 body.truncate( length );
158 mData.append( body.toUtf8() );
162 qDebug() <<
"fcgi: reading " << lengthstr <<
" bytes from " << ( request_body ?
"REQUEST_BODY" :
"stdin" );
167 for (
int i = 0; i < length; ++i )
169 mData.append( getchar() );
185 void QgsFcgiServerRequest::printRequestInfos(
const QUrl &
url )
189 const QStringList envVars
191 QStringLiteral(
"SERVER_NAME" ),
192 QStringLiteral(
"REQUEST_URI" ),
193 QStringLiteral(
"SCRIPT_NAME" ),
194 QStringLiteral(
"HTTPS" ),
195 QStringLiteral(
"REMOTE_ADDR" ),
196 QStringLiteral(
"REMOTE_HOST" ),
197 QStringLiteral(
"SERVER_PORT" ),
198 QStringLiteral(
"QUERY_STRING" ),
199 QStringLiteral(
"REMOTE_USER" ),
200 QStringLiteral(
"REMOTE_IDENT" ),
201 QStringLiteral(
"CONTENT_TYPE" ),
202 QStringLiteral(
"REQUEST_METHOD" ),
203 QStringLiteral(
"AUTH_TYPE" ),
204 QStringLiteral(
"HTTP_ACCEPT" ),
205 QStringLiteral(
"HTTP_USER_AGENT" ),
206 QStringLiteral(
"HTTP_PROXY" ),
207 QStringLiteral(
"NO_PROXY" ),
208 QStringLiteral(
"HTTP_AUTHORIZATION" ),
209 QStringLiteral(
"QGIS_PROJECT_FILE" )
216 for (
const auto &envVar : envVars )
218 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)