mirror of
https://github.com/lxsang/ant-http
synced 2024-12-26 00:38:21 +01:00
fix proxy protocol bug
This commit is contained in:
parent
520b99f94b
commit
8b483f0579
BIN
dist/antd-1.0.6b.tar.gz
vendored
BIN
dist/antd-1.0.6b.tar.gz
vendored
Binary file not shown.
@ -758,33 +758,31 @@ static void *proxy_monitor(void *data)
|
||||
antd_client_t *proxy = (antd_client_t *)dvalue(rq->request, "PROXY_HANDLE");
|
||||
antd_task_t* task = antd_create_task(NULL, data, NULL, rq->client->last_io);
|
||||
int ret, max_fd;
|
||||
fd_set read_flags;
|
||||
fd_set read_flags, write_flags;
|
||||
// first verify if the socket is ready
|
||||
FD_ZERO(&read_flags);
|
||||
FD_SET(rq->client->sock, &read_flags);
|
||||
FD_SET(proxy->sock, &read_flags);
|
||||
//FD_ZERO(&write_flags);
|
||||
//FD_SET(rq->client->sock, &write_flags);
|
||||
FD_ZERO(&write_flags);
|
||||
FD_SET(rq->client->sock, &write_flags);
|
||||
//FD_SET(proxy->sock, &write_flags);
|
||||
char *buf = NULL;
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 500;
|
||||
timeout.tv_usec = 5000;
|
||||
|
||||
max_fd = proxy->sock > rq->client->sock ? proxy->sock: rq->client->sock;
|
||||
|
||||
buf = (char *)malloc(BUFFLEN);
|
||||
//printf("start proxy monitor\n");
|
||||
// select
|
||||
ret = select(max_fd + 1, &read_flags, NULL, (fd_set *)0, &timeout);
|
||||
if(ret == -1)
|
||||
do
|
||||
{
|
||||
//antd_error(rq->client, 500, "");
|
||||
(void)close(proxy->sock);
|
||||
return task;
|
||||
}
|
||||
ret = select(max_fd + 1, &read_flags, &write_flags, (fd_set *)0, &timeout);
|
||||
if(ret > 0)
|
||||
{
|
||||
buf = (char *)malloc(BUFFLEN);
|
||||
if (FD_ISSET(rq->client->sock, &read_flags))
|
||||
|
||||
memset(buf, '\0', BUFFLEN);
|
||||
if (FD_ISSET(rq->client->sock, &read_flags) || FD_ISSET(rq->client->sock, &write_flags))
|
||||
{
|
||||
ret = antd_recv_upto(rq->client, buf, BUFFLEN);
|
||||
if(ret == -1)
|
||||
@ -806,12 +804,20 @@ static void *proxy_monitor(void *data)
|
||||
}
|
||||
antd_send(rq->client, buf, ret);
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
} while (ret > 0);
|
||||
free(buf);
|
||||
//printf("monitor return: %d\n", ret);
|
||||
if(ret == -1)
|
||||
{
|
||||
(void)close(proxy->sock);
|
||||
return task;
|
||||
}
|
||||
|
||||
task->handle = proxy_monitor;
|
||||
task->access_time = rq->client->last_io;
|
||||
// register event
|
||||
antd_task_bind_event(task, rq->client->sock, 0, TASK_EVT_ON_READABLE);
|
||||
antd_task_bind_event(task, rq->client->sock, 0, TASK_EVT_ON_READABLE | TASK_EVT_ON_WRITABLE);
|
||||
antd_task_bind_event(task, proxy->sock, 0, TASK_EVT_ON_READABLE);
|
||||
return task;
|
||||
}
|
||||
@ -840,6 +846,7 @@ static void *proxify(void *data)
|
||||
antd_error(rq->client, 503, "Service Unavailable");
|
||||
return task;
|
||||
}
|
||||
set_nonblock(sock_fd);
|
||||
proxy = (antd_client_t *)malloc(sizeof(antd_client_t));
|
||||
proxy->sock = sock_fd;
|
||||
proxy->ssl = NULL;
|
||||
@ -871,12 +878,11 @@ static void *proxify(void *data)
|
||||
}
|
||||
}
|
||||
(void)antd_send(proxy, "\r\n", 2);
|
||||
|
||||
// now monitor the proxy
|
||||
task->handle = proxy_monitor;
|
||||
task->access_time = rq->client->last_io;
|
||||
// register event
|
||||
antd_task_bind_event(task, rq->client->sock, 0, TASK_EVT_ON_READABLE);
|
||||
antd_task_bind_event(task, rq->client->sock, 0, TASK_EVT_ON_READABLE | TASK_EVT_ON_WRITABLE);
|
||||
antd_task_bind_event(task, proxy->sock, 0, TASK_EVT_ON_READABLE);
|
||||
return task;
|
||||
}
|
||||
@ -1121,9 +1127,16 @@ void *decode_post_request(void *data)
|
||||
if (strstr(ctype, FORM_URL_ENCODE))
|
||||
{
|
||||
char *pquery = post_data_decode(rq->client, clen);
|
||||
if(pquery)
|
||||
{
|
||||
decode_url_request(pquery, request);
|
||||
free(pquery);
|
||||
}
|
||||
else if(clen > 0)
|
||||
{
|
||||
task->handle = decode_post_request;
|
||||
}
|
||||
}
|
||||
else if (strstr(ctype, FORM_MULTI_PART))
|
||||
{
|
||||
free(task);
|
||||
@ -1132,6 +1145,7 @@ void *decode_post_request(void *data)
|
||||
else
|
||||
{
|
||||
char *pquery = post_data_decode(rq->client, clen);
|
||||
//printf("POST: %s\n", pquery);
|
||||
char *key = strstr(ctype, "/");
|
||||
if (key)
|
||||
key++;
|
||||
@ -1142,6 +1156,10 @@ void *decode_post_request(void *data)
|
||||
dput(request, key, strdup(pquery));
|
||||
free(pquery);
|
||||
}
|
||||
else if(clen > 0)
|
||||
{
|
||||
task->handle = decode_post_request;
|
||||
}
|
||||
}
|
||||
return task;
|
||||
}
|
||||
@ -1439,7 +1457,7 @@ char *post_data_decode(void *client, int len)
|
||||
int read = 0, stat = 1;
|
||||
while (readlen > 0 && stat > 0)
|
||||
{
|
||||
stat = antd_recv(client, ptr + read, readlen);
|
||||
stat = antd_recv_upto(client, ptr + read, readlen);
|
||||
if (stat > 0)
|
||||
{
|
||||
read += stat;
|
||||
|
8
httpd.c
8
httpd.c
@ -302,12 +302,12 @@ void antd_scheduler_destroy_data(void *data)
|
||||
|
||||
int antd_task_data_id(void *data)
|
||||
{
|
||||
antd_request_t *rq = (antd_request_t *)data;
|
||||
/*antd_request_t *rq = (antd_request_t *)data;
|
||||
if(!rq)
|
||||
return 0;
|
||||
return antd_scheduler_next_id(scheduler,rq->client->sock);
|
||||
//UNUSED(data);
|
||||
//return antd_scheduler_next_id(scheduler,0);
|
||||
return antd_scheduler_next_id(scheduler,rq->client->sock);*/
|
||||
UNUSED(data);
|
||||
return antd_scheduler_next_id(scheduler,0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -645,7 +645,6 @@ static void task_event_collect(bst_node_t* node, void** argv, int argc)
|
||||
antd_queue_t* exec_list = (antd_queue_t*) argv[0];
|
||||
bst_node_t** poll_list = (bst_node_t**) argv[1];
|
||||
int* pollsize = (int*) argv[2];
|
||||
|
||||
if(!task->events)
|
||||
{
|
||||
enqueue(exec_list, task);
|
||||
|
Loading…
Reference in New Issue
Block a user