fix 502 while proxied by nginx

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
This commit is contained in:
Jianhui Zhao
2021-01-18 19:13:54 +08:00
parent c44a2c65d2
commit 84675f5b20
2 changed files with 15 additions and 31 deletions
+14 -29
View File
@@ -39,7 +39,6 @@ void web_request_free(struct web_request_ctx *ctx)
{
struct rtty *rtty = ctx->rtty;
struct ev_loop *loop = rtty->loop;
struct buffer *wb = &rtty->wb;
if (ctx->sock > 0) {
ev_io_stop(loop, &ctx->ior);
@@ -48,13 +47,6 @@ void web_request_free(struct web_request_ctx *ctx)
close(ctx->sock);
}
if (rtty->sock > 0) {
buffer_put_u8(wb, MSG_TYPE_WEB);
buffer_put_u16be(wb, 2);
buffer_put_u16be(wb, ctx->id);
ev_io_start(loop, &rtty->iow);
}
buffer_free(&ctx->rb);
buffer_free(&ctx->wb);
@@ -77,7 +69,7 @@ static void on_net_read(struct ev_loop *loop, struct ev_io *w, int revents)
buffer_put_u8(wb, MSG_TYPE_WEB);
buffer_put_u16be(wb, 2 + ret);
buffer_put_u16be(wb, ctx->id);
buffer_put_u16be(wb, ctx->port);
buffer_put_data(wb, buf, ret);
ev_io_start(rtty->loop, &rtty->iow);
@@ -100,11 +92,6 @@ static void on_net_write(struct ev_loop *loop, struct ev_io *w, int revents)
return;
err:
if (ctx->closed) {
web_request_free(ctx);
return;
}
ev_io_stop(loop, w);
}
@@ -146,7 +133,7 @@ static struct web_request_ctx *find_exist_ctx(struct list_head *reqs, int port)
struct web_request_ctx *ctx;
list_for_each_entry(ctx, reqs, head)
if (ctx->id == port)
if (ctx->port == port)
return ctx;
return NULL;
}
@@ -154,24 +141,25 @@ static struct web_request_ctx *find_exist_ctx(struct list_head *reqs, int port)
void web_request(struct rtty *rtty, int len)
{
struct web_request_ctx *ctx;
int id, sock, req_len;
int port, sock, req_len;
struct sockaddr_in addrin = {
.sin_family = AF_INET
};
void *data;
id = buffer_pull_u16be(&rtty->rb);
if (len == 0) {
web_reqs_free(&rtty->web_reqs);
return;
}
port = buffer_pull_u16be(&rtty->rb);
req_len = len - 2;
ctx = find_exist_ctx(&rtty->web_reqs, id);
if (ctx) {
if (req_len == 0) {
ctx->closed = true;
if (ctx->sock > 0)
ev_io_start(rtty->loop, &ctx->iow);
return;
}
if (req_len == 0)
return;
ctx = find_exist_ctx(&rtty->web_reqs, port);
if (ctx) {
buffer_pull(&rtty->rb, NULL, 6);
req_len -= 6;
@@ -183,9 +171,6 @@ void web_request(struct rtty *rtty, int len)
return;
}
if (req_len == 0)
return;
addrin.sin_addr.s_addr = buffer_pull_u32(&rtty->rb);
addrin.sin_port = buffer_pull_u16(&rtty->rb);
@@ -193,7 +178,7 @@ void web_request(struct rtty *rtty, int len)
ctx = (struct web_request_ctx *)calloc(1, sizeof(struct web_request_ctx));
ctx->rtty = rtty;
ctx->id = id;
ctx->port = port;
ctx->active = ev_now(rtty->loop);
data = buffer_put(&ctx->wb, req_len);
+1 -2
View File
@@ -36,9 +36,8 @@ struct web_request_ctx {
struct buffer rb;
struct buffer wb;
ev_tstamp active;
bool closed;
int sock;
int id;
int port;
};
void web_request(struct rtty *rtty, int len);