More strict handling of connection: close
This commit is contained in:
@@ -50,6 +50,7 @@ struct AsyncSocket {
|
|||||||
template <bool> friend struct TemplatedApp;
|
template <bool> friend struct TemplatedApp;
|
||||||
template <bool, typename> friend struct WebSocketContextData;
|
template <bool, typename> friend struct WebSocketContextData;
|
||||||
template <typename, typename> friend struct TopicTree;
|
template <typename, typename> friend struct TopicTree;
|
||||||
|
template <bool> friend struct HttpResponse;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* Helper, do not use directly (todo: move to uSockets or de-crazify) */
|
/* Helper, do not use directly (todo: move to uSockets or de-crazify) */
|
||||||
|
|||||||
@@ -132,6 +132,21 @@ private:
|
|||||||
|
|
||||||
httpResponseData->markDone();
|
httpResponseData->markDone();
|
||||||
|
|
||||||
|
/* We need to check if we should close this socket here now */
|
||||||
|
if (!Super::isCorked()) {
|
||||||
|
if (httpResponseData->state & HttpResponseData<SSL>::HTTP_CONNECTION_CLOSE) {
|
||||||
|
if ((httpResponseData->state & HttpResponseData<SSL>::HTTP_RESPONSE_PENDING) == 0) {
|
||||||
|
if (((AsyncSocket<SSL> *) this)->getBufferedAmount() == 0) {
|
||||||
|
((AsyncSocket<SSL> *) this)->shutdown();
|
||||||
|
/* We need to force close after sending FIN since we want to hinder
|
||||||
|
* clients from keeping to send their huge data */
|
||||||
|
((AsyncSocket<SSL> *) this)->close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* tryEnd can never fail when in chunked mode, since we do not have tryWrite (yet), only write */
|
/* tryEnd can never fail when in chunked mode, since we do not have tryWrite (yet), only write */
|
||||||
Super::timeout(HTTP_TIMEOUT_S);
|
Super::timeout(HTTP_TIMEOUT_S);
|
||||||
return true;
|
return true;
|
||||||
@@ -182,6 +197,20 @@ private:
|
|||||||
/* Remove onAborted function if we reach the end */
|
/* Remove onAborted function if we reach the end */
|
||||||
if (httpResponseData->offset == totalSize) {
|
if (httpResponseData->offset == totalSize) {
|
||||||
httpResponseData->markDone();
|
httpResponseData->markDone();
|
||||||
|
|
||||||
|
/* We need to check if we should close this socket here now */
|
||||||
|
if (!Super::isCorked()) {
|
||||||
|
if (httpResponseData->state & HttpResponseData<SSL>::HTTP_CONNECTION_CLOSE) {
|
||||||
|
if ((httpResponseData->state & HttpResponseData<SSL>::HTTP_RESPONSE_PENDING) == 0) {
|
||||||
|
if (((AsyncSocket<SSL> *) this)->getBufferedAmount() == 0) {
|
||||||
|
((AsyncSocket<SSL> *) this)->shutdown();
|
||||||
|
/* We need to force close after sending FIN since we want to hinder
|
||||||
|
* clients from keeping to send their huge data */
|
||||||
|
((AsyncSocket<SSL> *) this)->close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
@@ -472,6 +501,19 @@ public:
|
|||||||
/* This behavior should equal the behavior in HttpContext when uncorking fails */
|
/* This behavior should equal the behavior in HttpContext when uncorking fails */
|
||||||
Super::timeout(HTTP_TIMEOUT_S);
|
Super::timeout(HTTP_TIMEOUT_S);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If we have no backbuffer and we are connection close and we responded fully then close */
|
||||||
|
HttpResponseData<SSL> *httpResponseData = getHttpResponseData();
|
||||||
|
if (httpResponseData->state & HttpResponseData<SSL>::HTTP_CONNECTION_CLOSE) {
|
||||||
|
if ((httpResponseData->state & HttpResponseData<SSL>::HTTP_RESPONSE_PENDING) == 0) {
|
||||||
|
if (((AsyncSocket<SSL> *) this)->getBufferedAmount() == 0) {
|
||||||
|
((AsyncSocket<SSL> *) this)->shutdown();
|
||||||
|
/* We need to force close after sending FIN since we want to hinder
|
||||||
|
* clients from keeping to send their huge data */
|
||||||
|
((AsyncSocket<SSL> *) this)->close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* We are already corked, or can't cork so let's just call the handler */
|
/* We are already corked, or can't cork so let's just call the handler */
|
||||||
handler();
|
handler();
|
||||||
|
|||||||
Reference in New Issue
Block a user