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" ),
214 QStringLiteral(
"QGIS_SERVER_IGNORE_BAD_LAYERS" )
221 for (
const auto &envVar : envVars )
223 if ( getenv( envVar.toStdString().c_str() ) )