summaryrefslogtreecommitdiff
path: root/ot_http.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-10-27 03:05:43 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-10-27 03:05:43 +0100
commitfa0f7ee6dba3ba14a6fc1172e04a161f514d94b0 (patch)
treef418d15698caf353e25557f8139b3d87a1513b32 /ot_http.c
parent0d6e0044a104176d6d6f2111fda1d7c1f160a583 (diff)
Revive http keep alive to save tcp connection setup costs
Diffstat (limited to 'ot_http.c')
-rw-r--r--ot_http.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/ot_http.c b/ot_http.c
index 36819c7..14952b5 100644
--- a/ot_http.c
+++ b/ot_http.c
@@ -727,6 +727,24 @@ ssize_t http_handle_request(const int64_t sock, struct ot_workstruct *ws) {
727 /* Tell subroutines where to put reply data */ 727 /* Tell subroutines where to put reply data */
728 ws->reply = ws->outbuf + SUCCESS_HTTP_HEADER_LENGTH; 728 ws->reply = ws->outbuf + SUCCESS_HTTP_HEADER_LENGTH;
729 729
730 /* Find out if the client wants to keep this connection alive, before any
731 subroutine gets to answer: an error reply finishes with the connection
732 on its way out, and ws outlives the connection it was serving */
733 ws->keep_alive = 0;
734#ifdef WANT_KEEPALIVE
735 if ((write_ptr = http_header(ws->request, ws->header_size, "connection")) && (*write_ptr == 'K' || *write_ptr == 'k'))
736 ws->keep_alive = 1;
737#endif
738 {
739 struct http_data *connection = fdstate_cookie(sock);
740 if (connection) {
741 if (ws->keep_alive)
742 connection->flag |= STRUCT_HTTP_FLAG_KEEPALIVE;
743 else
744 connection->flag &= ~STRUCT_HTTP_FLAG_KEEPALIVE;
745 }
746 }
747
730 /* This one implicitely tests strlen < 5, too -- remember, it is \n terminated */ 748 /* This one implicitely tests strlen < 5, too -- remember, it is \n terminated */
731 if (memcmp(read_ptr, "GET /", 5)) 749 if (memcmp(read_ptr, "GET /", 5))
732 HTTPERROR_400; 750 HTTPERROR_400;
@@ -763,14 +781,6 @@ ssize_t http_handle_request(const int64_t sock, struct ot_workstruct *ws) {
763 else 781 else
764 HTTPERROR_404; 782 HTTPERROR_404;
765 783
766 /* Find out if the client wants to keep this connection alive */
767 ws->keep_alive = 0;
768#ifdef WANT_KEEPALIVE
769 read_ptr = http_header(ws->request, ws->header_size, "connection");
770 if (read_ptr && (*read_ptr == 'K' || *read_ptr == 'k'))
771 ws->keep_alive = 1;
772#endif
773
774 /* If routines handled sending themselves, just return */ 784 /* If routines handled sending themselves, just return */
775 if (ws->reply_size == -2) 785 if (ws->reply_size == -2)
776 return 0; 786 return 0;