@@ -33,6 +33,7 @@ QHttpConnection::QHttpConnection(QTcpSocket *socket, QObject *parent)
33
33
: QObject(parent)
34
34
, m_socket(socket)
35
35
, m_parser(0 )
36
+ , m_request(0 )
36
37
{
37
38
qDebug () << " Got new connection" << socket->peerAddress () << socket->peerPort ();
38
39
@@ -50,7 +51,7 @@ QHttpConnection::QHttpConnection(QTcpSocket *socket, QObject *parent)
50
51
m_parser->data = this ;
51
52
52
53
connect (socket, SIGNAL (readyRead ()), this , SLOT (parseRequest ()));
53
- connect (socket, SIGNAL (disconnected ()), this , SLOT (deleteLater ()));
54
+ connect (socket, SIGNAL (disconnected ()), this , SLOT (socketDisconnected ()));
54
55
}
55
56
56
57
QHttpConnection::~QHttpConnection ()
@@ -62,6 +63,19 @@ QHttpConnection::~QHttpConnection()
62
63
m_parser = 0 ;
63
64
}
64
65
66
+ void QHttpConnection::socketDisconnected ()
67
+ {
68
+ if (m_request) {
69
+ if (m_request->successful ()) {
70
+ return ;
71
+ }
72
+ m_request->setSuccessful (false );
73
+ emit m_request->end ();
74
+ }
75
+
76
+ deleteLater ();
77
+ }
78
+
65
79
void QHttpConnection::parseRequest ()
66
80
{
67
81
Q_ASSERT (m_parser);
@@ -144,6 +158,7 @@ int QHttpConnection::HeadersComplete(http_parser *parser)
144
158
if ( parser->http_major < 1 || parser->http_minor < 1 )
145
159
response->m_keepAlive = false ;
146
160
161
+ connect (theConnection, SIGNAL (destroyed ()), response, SLOT (connectionClosed ()));
147
162
connect (response, SIGNAL (done ()), theConnection, SLOT (responseDone ()));
148
163
149
164
// we are good to go!
@@ -157,6 +172,7 @@ int QHttpConnection::MessageComplete(http_parser *parser)
157
172
QHttpConnection *theConnection = (QHttpConnection *)parser->data ;
158
173
Q_ASSERT (theConnection->m_request );
159
174
175
+ theConnection->m_request ->setSuccessful (true );
160
176
emit theConnection->m_request ->end ();
161
177
return 0 ;
162
178
}
0 commit comments