Update, tests.
Build and Test / build (push) Successful in 25s

This commit is contained in:
2025-12-02 00:50:05 +01:00
parent dbd4fe22ed
commit e5ae782433
11 changed files with 1616 additions and 18 deletions
+1 -1
View File
@@ -244,7 +244,7 @@ int config_load(const char *filename) {
route->patches.rule_count++;
}
if (route->patches.rule_count > 0) {
log_info("Loaded %d patch rules for %s", route->hostname);
log_info("Loaded %d patch rules for %s", route->patches.rule_count, route->hostname);
}
}
+47 -7
View File
@@ -168,6 +168,15 @@ void connection_close(int fd) {
log_debug("Upstream fd %d is closing. Resetting client fd %d to READING_HEADERS.", fd, pair->fd);
pair->state = CLIENT_STATE_READING_HEADERS;
pair->pair = NULL;
pair->route = NULL;
pair->content_type_checked = 0;
pair->is_textual_content = 0;
pair->response_headers_parsed = 0;
pair->original_content_length = 0;
pair->content_length_delta = 0;
pair->patch_blocked = 0;
pair->half_closed = 0;
pair->write_shutdown = 0;
} else if (conn->type == CONN_TYPE_CLIENT && pair->type == CONN_TYPE_UPSTREAM) {
log_debug("Client fd %d is closing. Closing orphaned upstream pair fd %d.", fd, pair->fd);
pair->pair = NULL;
@@ -698,6 +707,31 @@ static void handle_forwarding(connection_t *conn) {
int bytes_read = connection_do_read(conn);
if (conn->type == CONN_TYPE_CLIENT && bytes_read > 0) {
char *data_start = conn->read_buf.data + conn->read_buf.head;
size_t data_len = buffer_available_read(&conn->read_buf);
if (data_len >= 4 && http_is_request_start(data_start, data_len)) {
log_debug("Pipelined request detected in handle_forwarding on fd %d, closing upstream fd %d",
conn->fd, pair->fd);
connection_close(pair->fd);
conn->pair = NULL;
conn->state = CLIENT_STATE_READING_HEADERS;
conn->content_type_checked = 0;
conn->is_textual_content = 0;
conn->response_headers_parsed = 0;
conn->original_content_length = 0;
conn->content_length_delta = 0;
conn->patch_blocked = 0;
conn->half_closed = 0;
conn->write_shutdown = 0;
handle_client_read(conn);
return;
}
}
if (bytes_read == 0) {
log_debug("EOF on fd %d, performing half-close on pair fd %d", conn->fd, pair->fd);
conn->half_closed = 1;
@@ -841,14 +875,20 @@ static void handle_ssl_handshake(connection_t *conn) {
connection_t *client = conn->pair;
if (buffer_available_read(&client->read_buf) > 0) {
char *data_start = client->read_buf.data + client->read_buf.head;
size_t data_len = buffer_available_read(&client->read_buf);
if (buffer_ensure_capacity(&conn->write_buf, conn->write_buf.tail + data_len) == 0) {
memcpy(conn->write_buf.data + conn->write_buf.tail,
client->read_buf.data + client->read_buf.head,
data_len);
conn->write_buf.tail += data_len;
buffer_consume(&client->read_buf, data_len);
log_debug("Forwarding %zu bytes of buffered request data after SSL handshake", data_len);
if (data_len >= 4 && http_is_request_start(data_start, data_len)) {
log_debug("New HTTP request detected in client buffer after SSL handshake, not forwarding raw");
} else {
if (buffer_ensure_capacity(&conn->write_buf, conn->write_buf.tail + data_len) == 0) {
memcpy(conn->write_buf.data + conn->write_buf.tail,
client->read_buf.data + client->read_buf.head,
data_len);
conn->write_buf.tail += data_len;
buffer_consume(&client->read_buf, data_len);
log_debug("Forwarding %zu bytes of buffered request data after SSL handshake", data_len);
}
}
}
}
+4 -4
View File
@@ -34,7 +34,7 @@ void health_check_init(void) {
free(health_states);
}
health_state_count = config.route_count;
health_state_count = config->route_count;
if (health_state_count <= 0) {
health_states = NULL;
pthread_mutex_unlock(&health_mutex);
@@ -49,9 +49,9 @@ void health_check_init(void) {
}
for (int i = 0; i < health_state_count; i++) {
strncpy(health_states[i].hostname, config.routes[i].hostname, sizeof(health_states[i].hostname) - 1);
strncpy(health_states[i].upstream_host, config.routes[i].upstream_host, sizeof(health_states[i].upstream_host) - 1);
health_states[i].upstream_port = config.routes[i].upstream_port;
strncpy(health_states[i].hostname, config->routes[i].hostname, sizeof(health_states[i].hostname) - 1);
strncpy(health_states[i].upstream_host, config->routes[i].upstream_host, sizeof(health_states[i].upstream_host) - 1);
health_states[i].upstream_port = config->routes[i].upstream_port;
health_states[i].healthy = 1;
health_states[i].consecutive_failures = 0;
health_states[i].last_check = 0;