fixes wrong response connection header on keep-alive

This commit is contained in:
overflowerror 2021-05-13 12:52:22 +02:00
parent 2788c6f94b
commit d12a968cc2

View file

@ -308,6 +308,8 @@ void safeEndConnection(struct connection* connection, bool force) {
// TODO: Look into how self can be joined // TODO: Look into how self can be joined
// (because this function will be called in response or encoder thread) // (because this function will be called in response or encoder thread)
void resetPersistentConnection(struct connection* connection) { void resetPersistentConnection(struct connection* connection) {
debug("networking: resetting persistent connection to initial state");
pthread_t self = pthread_self(); pthread_t self = pthread_self();
// kill request thread so that the connection doesn't get killed // kill request thread so that the connection doesn't get killed
@ -322,9 +324,7 @@ void resetPersistentConnection(struct connection* connection) {
// wait for encoder // wait for encoder
if (connection->threads.encoder != PTHREAD_NULL) { if (connection->threads.encoder != PTHREAD_NULL) {
// if caller is encoder stopThread will to nothing // if caller is encoder stopThread will to nothing
debug("stopping encoder thread");
stopThread(self, &(connection->threads.encoder), false); stopThread(self, &(connection->threads.encoder), false);
debug("stopped encoder thread");
} }
// free request specific data // free request specific data
@ -400,7 +400,7 @@ void* chunkedTransferEncodingThread(void* _data) {
chunks++; chunks++;
} }
debug("networking: chunked transfer encoding: %lld bytes send in %lld chunks", total, chunks); debug("networking: chunked transfer encoding: %lld bytes sent in %lld chunks", total, chunks);
if (0 == tmp) { if (0 == tmp) {
// send last chunk flag // send last chunk flag
@ -480,9 +480,13 @@ int sendHeader(int statusCode, struct headers* headers, struct request* request)
bool chunkedTransferEncoding = false; bool chunkedTransferEncoding = false;
if (connection->isPersistent) { if (connection->isPersistent) {
debug("networking: this connection is persistent");
headers_mod(headers, "Connection", "keep-alive"); headers_mod(headers, "Connection", "keep-alive");
if (headers_get(headers, "Content-Length") == NULL) { if (headers_get(headers, "Content-Length") == NULL) {
debug("networking: this response is chunked");
headers_mod(headers, "Transfer-Encoding", "chunked"); headers_mod(headers, "Transfer-Encoding", "chunked");
chunkedTransferEncoding = true; chunkedTransferEncoding = true;
} }
@ -754,9 +758,9 @@ void dataHandler(int signo) {
// HTTP 1.1 uses persistent connections unless specified otherwise // HTTP 1.1 uses persistent connections unless specified otherwise
connection->isPersistent = true; connection->isPersistent = true;
} }
} else if (strcasecmp(connectionHeader, "close")) { } else if (strcasecmp(connectionHeader, "close") == 0) {
connection->isPersistent = false; connection->isPersistent = false;
} else if (strcasecmp(connectionHeader, "keep-alive")) { } else if (strcasecmp(connectionHeader, "keep-alive") == 0) {
connection->isPersistent = true; connection->isPersistent = true;
} }