|
|
@ -31,6 +31,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <QTcpSocket> |
|
|
|
#include <QTcpSocket> |
|
|
|
#include <QDebug> |
|
|
|
#include <QDebug> |
|
|
|
|
|
|
|
#include <QRegExp> |
|
|
|
#include "types.h" |
|
|
|
#include "types.h" |
|
|
|
#include "requestparser.h" |
|
|
|
#include "requestparser.h" |
|
|
|
#include "responsegenerator.h" |
|
|
|
#include "responsegenerator.h" |
|
|
@ -85,26 +86,13 @@ void Connection::sendResponse(const Response &response) |
|
|
|
|
|
|
|
|
|
|
|
bool Connection::acceptsGzipEncoding(const QString &encoding) |
|
|
|
bool Connection::acceptsGzipEncoding(const QString &encoding) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int pos = encoding.indexOf("gzip", 0, Qt::CaseInsensitive); |
|
|
|
QRegExp rx("(gzip)(;q=([^,]+))?"); |
|
|
|
if (pos == -1) |
|
|
|
if (rx.indexIn(encoding) >= 0) { |
|
|
|
return false; |
|
|
|
if (rx.cap(2).size() > 0) |
|
|
|
|
|
|
|
// check if quality factor > 0
|
|
|
|
// Let's see if there's a qvalue of 0.0 following
|
|
|
|
return (rx.cap(3).toDouble() > 0); |
|
|
|
if (encoding[pos + 4] != ';') //there isn't, so it accepts gzip anyway
|
|
|
|
// if quality factor is not specified, then it's 1
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
//So let's find = and the next comma
|
|
|
|
return false; |
|
|
|
pos = encoding.indexOf("=", pos + 4, Qt::CaseInsensitive); |
|
|
|
|
|
|
|
int comma_pos = encoding.indexOf(",", pos, Qt::CaseInsensitive); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString value; |
|
|
|
|
|
|
|
if (comma_pos == -1) |
|
|
|
|
|
|
|
value = encoding.mid(pos + 1, comma_pos); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
value = encoding.mid(pos + 1, comma_pos - (pos + 1)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (value.toDouble() == 0.0) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|