diff --git a/http-relay.c b/http-relay.c index e7a5217..d18fb7a 100644 --- a/http-relay.c +++ b/http-relay.c @@ -412,6 +412,8 @@ static int httpr_toss_http_firstline(redsocks_client *client) if (httpr_buffer_append(&nbuff, "\x0d\x0a", 2) != 0) goto addition_fail; + free_null(httpr->firstline); + httpr->firstline = calloc(nbuff.len + 1, 1); strcpy(httpr->firstline, nbuff.buff); httpr_buffer_fini(&nbuff); @@ -460,6 +462,12 @@ static void httpr_client_read_content(struct bufferevent *buffev, redsocks_clien } } +static void httpr_client_eof(redsocks_client *client) +{ + client->state = httpr_recv_request; + redsocks_connect_relay(client); +} + static void httpr_client_read_cb(struct bufferevent *buffev, void *_arg) { redsocks_client *client = _arg; @@ -575,6 +583,7 @@ relay_subsys http_relay_subsys = .connect_relay = httpr_connect_relay, .readcb = httpr_relay_read_cb, .writecb = httpr_relay_write_cb, + .client_eof = httpr_client_eof, }; /* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */ diff --git a/redsocks.c b/redsocks.c index 020ed12..49814c2 100644 --- a/redsocks.c +++ b/redsocks.c @@ -412,7 +412,10 @@ static void redsocks_event_error(struct bufferevent *buffev, short what, void *_ redsocks_shutdown(client, buffev, SHUT_RD); - if (EVBUFFER_LENGTH(antiev->output) == 0) + if (buffev == client->client && antiev == NULL) { + if (client->instance->relay_ss->client_eof) + client->instance->relay_ss->client_eof(client); + } else if (EVBUFFER_LENGTH(antiev->output) == 0) redsocks_shutdown(client, antiev, SHUT_WR); } else { diff --git a/redsocks.h b/redsocks.h index 8fca050..8e2313c 100644 --- a/redsocks.h +++ b/redsocks.h @@ -25,6 +25,8 @@ typedef struct relay_subsys_t { void (*fini)(struct redsocks_client_t *client); // connect_relay (if any) is called instead of redsocks_connect_relay after client connection acceptance void (*connect_relay)(struct redsocks_client_t *client); + // client_eof is called while relay is not set up but EOF from client is received + void (*client_eof)(struct redsocks_client_t *client); } relay_subsys; typedef struct redsocks_config_t {