Skip to content

Commit

Permalink
Server standalone: read hostname and port from HOST header (if any)
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Apr 26, 2020
1 parent 3145353 commit 631fe6f
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/server/qgis_mapserver.cpp
Expand Up @@ -322,15 +322,6 @@ int main( int argc, char *argv[] )
throw HttpException( QStringLiteral( "HTTP error unsupported method: %1" ).arg( methodString ) );
}

// Build URL from env ...
QString url { qgetenv( "REQUEST_URI" ) };
// ... or from server ip/port and request path
if ( url.isEmpty() )
{
const QString path { firstLinePieces.at( 1 )};
url = QStringLiteral( "http://%1:%2%3" ).arg( ipAddress ).arg( port ).arg( path );
}

const QString protocol { firstLinePieces.at( 2 )};
if ( protocol != QStringLiteral( "HTTP/1.0" ) && protocol != QStringLiteral( "HTTP/1.1" ) )
{
Expand All @@ -357,6 +348,23 @@ int main( int argc, char *argv[] )
}
}

// Build URL from env ...
QString url { qgetenv( "REQUEST_URI" ) };
// ... or from server ip/port and request path
if ( url.isEmpty() )
{
const QString path { firstLinePieces.at( 1 )};
// Take Host header if defined
if ( headers.contains( QStringLiteral( "Host" ) ) )
{
url = QStringLiteral( "http://%1%2" ).arg( headers.value( QStringLiteral( "Host" ) ) ).arg( path );
}
else
{
url = QStringLiteral( "http://%2:%3%4" ).arg( ipAddress ).arg( port ).arg( path );
}
}

// Inefficient copy :(
QByteArray data { incomingData.mid( endHeadersPos + 4 ).toUtf8() };

Expand Down

0 comments on commit 631fe6f

Please sign in to comment.