diff --git a/include/lighttpd/connection.h b/include/lighttpd/connection.h index 496e2ef..4312c4e 100644 --- a/include/lighttpd/connection.h +++ b/include/lighttpd/connection.h @@ -93,17 +93,15 @@ struct liConnection { } stats; }; +/* Internal functions */ LI_API liConnection* li_connection_new(liWorker *wrk); -LI_API void li_connection_reset(liConnection *con); -LI_API void li_connection_reset_keep_alive(liConnection *con); LI_API void li_connection_free(liConnection *con); +LI_API void li_connection_reset(liConnection *con); -LI_API void li_connection_error(liConnection *con); -LI_API void li_connection_internal_error(liConnection *con); - -LI_API void li_connection_handle_direct(liConnection *con); -LI_API void li_connection_handle_indirect(liConnection *con, liPlugin *p); +/** aborts an active connection, calls all plugin cleanup handlers */ +LI_API void li_connection_error(liConnection *con); /* used in worker.c */ +/* public function */ LI_API gchar *li_connection_state_str(liConnectionState state); #endif diff --git a/include/lighttpd/response.h b/include/lighttpd/response.h index fa1890c..3e2a3f1 100644 --- a/include/lighttpd/response.h +++ b/include/lighttpd/response.h @@ -15,7 +15,7 @@ LI_API void li_response_init(liResponse *resp); LI_API void li_response_reset(liResponse *resp); LI_API void li_response_clear(liResponse *resp); -LI_API void li_response_send_headers(liConnection *con); +LI_API gboolean li_response_send_headers(liConnection *con); LI_API void li_response_send_error_page(liConnection *con); #endif diff --git a/src/main/connection.c b/src/main/connection.c index 52933ba..95ec627 100644 --- a/src/main/connection.c +++ b/src/main/connection.c @@ -5,6 +5,9 @@ /* only call it from the worker context the con belongs to */ void worker_con_put(liConnection *con); /* worker.c */ +static void li_connection_reset_keep_alive(liConnection *con); +static void li_connection_internal_error(liConnection *con); + static void parse_request_body(liConnection *con) { if ((con->state > LI_CON_STATE_HANDLE_MAINVR || con->mainvr->state >= LI_VRS_READ_CONTENT) && !con->in->is_closed) { li_ev_io_add_events(con->wrk->loop, &con->sock_watcher, EV_READ); @@ -30,11 +33,15 @@ static void forward_response_body(liConnection *con) { liVRequest *vr = con->mainvr; if (con->state >= LI_CON_STATE_HANDLE_MAINVR) { if (!con->response_headers_sent) { - con->response_headers_sent = TRUE; if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "%s", "write response headers"); } - li_response_send_headers(con); + con->response_headers_sent = TRUE; + if (!li_response_send_headers(con)) { + con->response_headers_sent = FALSE; + li_connection_internal_error(con); + return; + } } if (vr->response.transfer_encoding & LI_HTTP_TRANSFER_ENCODING_CHUNKED) { @@ -101,14 +108,18 @@ void li_connection_error(liConnection *con) { worker_con_put(con); } -void li_connection_internal_error(liConnection *con) { +static void li_connection_internal_error(liConnection *con) { liVRequest *vr = con->mainvr; if (con->response_headers_sent) { - VR_ERROR(vr, "%s", "Couldn't send '500 Internal Error': headers already sent"); + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { + VR_DEBUG(vr, "%s", "Couldn't send '500 Internal Error': headers already sent"); + } li_connection_error(con); } else { liHttpVersion v; - VR_ERROR(vr, "%s", "internal error"); + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { + VR_DEBUG(vr, "%s", "internal error"); + } /* We only need the http version from the http request */ v = con->mainvr->request.http_version; @@ -557,8 +568,7 @@ void li_connection_reset(liConnection *con) { con->throttled = FALSE; } -void server_check_keepalive(liServer *srv); -void li_connection_reset_keep_alive(liConnection *con) { +static void li_connection_reset_keep_alive(liConnection *con) { liVRequest *vr = con->mainvr; ev_timer_stop(con->wrk->loop, &con->keep_alive_data.watcher); { diff --git a/src/main/response.c b/src/main/response.c index 97c6ef8..2dfecc7 100644 --- a/src/main/response.c +++ b/src/main/response.c @@ -20,15 +20,13 @@ void li_response_clear(liResponse *resp) { resp->transfer_encoding = LI_HTTP_TRANSFER_ENCODING_IDENTITY; } -void li_response_send_headers(liConnection *con) { +gboolean li_response_send_headers(liConnection *con) { GString *head; liVRequest *vr = con->mainvr; if (vr->response.http_status < 100 || vr->response.http_status > 999) { VR_ERROR(vr, "wrong status: %i", vr->response.http_status); - con->response_headers_sent = FALSE; - li_connection_internal_error(con); - return; + return FALSE; } head = g_string_sized_new(8*1024-1); @@ -128,6 +126,8 @@ void li_response_send_headers(liConnection *con) { g_string_append_len(head, CONST_STR_LEN("\r\n")); li_chunkqueue_append_string(con->raw_out, head); + + return TRUE; } #define SET_LEN_AND_RETURN_STR(x) \