12 : QThread(), useQtSettings(true)
14 Q_ASSERT(settings != 0);
15 Q_ASSERT(requestHandler != 0);
28 socket->moveToThread(
this);
32 connect(
socket, SIGNAL(readyRead()), SLOT(
read()));
37 qDebug(
"HttpConnectionHandler (%p): constructed",
this);
44 Q_ASSERT(settings != 0);
45 Q_ASSERT(requestHandler != 0);
58 socket->moveToThread(
this);
62 connect(
socket, SIGNAL(readyRead()), SLOT(
read()));
67 qDebug(
"HttpConnectionHandler (%p): constructed",
this);
76 qDebug(
"HttpConnectionHandler (%p): destroyed",
this);
86 QSslSocket* sslSocket=
new QSslSocket();
89 qDebug(
"HttpConnectionHandler (%p): SSL is enabled",
this);
101 qDebug(
"HttpConnectionHandler (%p): thread started",
this);
109 qCritical(
"HttpConnectionHandler (%p): an uncatched exception occurred in the thread",
this);
115 qDebug(
"HttpConnectionHandler (%p): thread stopped",
this);
123 qDebug(
"HttpConnectionHandler (%p): handle new connection",
this);
126 Q_ASSERT(
socket->isOpen()==
false);
130 socket->connectToHost(
"",0);
133 if (!
socket->setSocketDescriptor(socketDescriptor))
135 qCritical(
"HttpConnectionHandler (%p): cannot initialize socket: %s",
this,qPrintable(
socket->errorString()));
139 #ifndef QT_NO_OPENSSL 143 qDebug(
"HttpConnectionHandler (%p): Starting encryption",
this);
144 ((QSslSocket*)
socket)->startServerEncryption();
170 qDebug(
"HttpConnectionHandler (%p): read timeout occurred",
this);
175 while(
socket->bytesToWrite())
socket->waitForBytesWritten();
176 socket->disconnectFromHost();
184 qDebug(
"HttpConnectionHandler (%p): disconnected",
this);
193 while (
socket->bytesAvailable())
196 qDebug(
"HttpConnectionHandler (%p): read input",
this);
225 socket->write(
"HTTP/1.1 413 entity too large\r\nConnection: close\r\n\r\n413 Entity too large\r\n");
226 while(
socket->bytesToWrite())
socket->waitForBytesWritten();
227 socket->disconnectFromHost();
237 qDebug(
"HttpConnectionHandler (%p): received request from %s (%s) %s",
248 response.setHeader(
"Connection",
"close");
258 closeConnection=
true;
259 response.setHeader(
"Connection",
"close");
270 qCritical(
"HttpConnectionHandler (%p): An uncatched exception occurred in the request handler",
this);
274 if (!response.hasSentLastPart())
276 response.write(QByteArray(),
true);
280 qDebug(
"HttpConnectionHandler (%p): finished request",
this);
284 if (!closeConnection)
287 bool closeResponse=QString::compare(response.getHeaders().value(
"Connection"),
"close",Qt::CaseInsensitive)==0;
288 if (closeResponse==
true)
290 closeConnection=
true;
296 bool hasContentLength=response.getHeaders().contains(
"Content-Length");
297 if (!hasContentLength)
299 bool hasChunkedMode=QString::compare(response.getHeaders().value(
"Transfer-Encoding"),
"chunked",Qt::CaseInsensitive)==0;
302 closeConnection=
true;
311 while(
socket->bytesToWrite())
socket->waitForBytesWritten();
312 socket->disconnectFromHost();
RequestStatus getStatus() const
QByteArray getPath() const
QSslConfiguration * sslConfiguration
HttpConnectionHandler(QSettings *settings, HttpRequestHandler *requestHandler, QSslConfiguration *sslConfiguration=NULL)
void handleConnection(tSocketDescriptor socketDescriptor)
QByteArray getVersion() const
HttpRequestHandler * requestHandler
QByteArray getHeader(const QByteArray &name) const
const HttpListenerSettings * listenerSettings
void readFromSocket(QTcpSocket *socket)
HttpRequest * currentRequest
virtual ~HttpConnectionHandler()
QHostAddress getPeerAddress() const
QByteArray getMethod() const
virtual void service(HttpRequest &request, HttpResponse &response)