Implement hasResponded

This commit is contained in:
Alex Hultman
2019-01-18 17:20:21 +01:00
parent 2caefa9d96
commit 19aa6ec9af
3 changed files with 18 additions and 10 deletions
+2 -1
View File
@@ -135,8 +135,9 @@ private:
HttpResponseData<SSL> *httpResponseData = (HttpResponseData<SSL> *) static_dispatch(us_ssl_socket_ext, us_socket_ext)((SOCKET_TYPE *) s); HttpResponseData<SSL> *httpResponseData = (HttpResponseData<SSL> *) static_dispatch(us_ssl_socket_ext, us_socket_ext)((SOCKET_TYPE *) s);
httpResponseData->offset = 0; httpResponseData->offset = 0;
httpResponseData->state = 0; httpResponseData->state = 0;
httpResponseData->state |= HttpResponseData<SSL>::HTTP_RESPONSE_PENDING;
/* Route the method and URL */ /* Route the method and URL (unhandled should close or end it by default) */
httpContextData->router.route(httpRequest->getMethod(), httpRequest->getUrl(), { httpContextData->router.route(httpRequest->getMethod(), httpRequest->getUrl(), {
(HttpResponse<SSL> *) s, httpRequest (HttpResponse<SSL> *) s, httpRequest
}); });
+15 -8
View File
@@ -63,6 +63,16 @@ private:
Super::write(buf, length); Super::write(buf, length);
} }
/* When we are done with a response we mark it like so */
void markDone(HttpResponseData<SSL> *httpResponseData) {
httpResponseData->onAborted = nullptr;
/* Also remove onWritable so that we do not emit when draining behind the scenes. */
httpResponseData->onWritable = nullptr;
/* We are done with this request */
httpResponseData->state &= ~HttpResponseData<SSL>::HTTP_RESPONSE_PENDING;
}
/* Returns true on success, indicating that it might be feasible to write more data. /* Returns true on success, indicating that it might be feasible to write more data.
* Will start timeout if stream reaches totalSize or write failure. */ * Will start timeout if stream reaches totalSize or write failure. */
bool internalEnd(std::string_view data, int totalSize, bool optional) { bool internalEnd(std::string_view data, int totalSize, bool optional) {
@@ -92,7 +102,7 @@ private:
/* Terminating 0 chunk */ /* Terminating 0 chunk */
Super::write("\r\n0\r\n\r\n", 7); Super::write("\r\n0\r\n\r\n", 7);
// todo: here we reach the end, so remove onAborted, onWritable, and set HTTP_RESPONDED_TO markDone(httpResponseData);
/* 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);
@@ -131,11 +141,7 @@ 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->onAborted = nullptr; markDone(httpResponseData);
/* Also remove onWritable so that we do not emit when draining behind the scenes. */
httpResponseData->onWritable = nullptr;
// todo: set HTTP_RESPONDED_TO here and use in the emittance of new requests
} }
return success; return success;
@@ -236,8 +242,9 @@ public:
/* Checking if we have fully responded and are ready for another request */ /* Checking if we have fully responded and are ready for another request */
bool hasResponded() { bool hasResponded() {
// todo: implement HttpResponseData<SSL> *httpResponseData = getHttpResponseData();
return true;
return !(httpResponseData->state & HttpResponseData<SSL>::HTTP_RESPONSE_PENDING);
} }
/* Attach handler for writable HTTP response */ /* Attach handler for writable HTTP response */
+1 -1
View File
@@ -38,7 +38,7 @@ private:
HTTP_STATUS_CALLED = 1, // used HTTP_STATUS_CALLED = 1, // used
HTTP_WRITE_CALLED = 2, // used HTTP_WRITE_CALLED = 2, // used
HTTP_END_CALLED = 4, // used HTTP_END_CALLED = 4, // used
HTTP_RESPONDED_TO = 8, // used HTTP_RESPONSE_PENDING = 8, // used
HTTP_ENDED_STREAM_OUT = 16 // not used HTTP_ENDED_STREAM_OUT = 16 // not used
}; };