optimization
This commit is contained in:
parent
4b40444806
commit
9ba3f7dcf1
@ -8,16 +8,16 @@ global {
|
|||||||
}
|
}
|
||||||
|
|
||||||
http {
|
http {
|
||||||
http_ip=47.240.75.93;
|
http_ip=8.210.203.112;
|
||||||
http_port=124;
|
http_port=124;
|
||||||
http_del="x-online-host,X-Online-Host,host,Host";
|
http_del="Host";
|
||||||
http_first="[M] http://[host][U] [V]\r\nHost: [host]\r\n";
|
http_first="[M] http://[host][U] [V]\r\nHost: [host]\r\n";
|
||||||
//strrep="Windows NT 10.0->Linux";
|
//strrep="Windows NT 10.0->Linux";
|
||||||
//regrep="Host:*.+?->Host: [host]:80";
|
//regrep="Host:*.+?->Host: [host]:80";
|
||||||
}
|
}
|
||||||
|
|
||||||
https {
|
https {
|
||||||
https_ip=47.240.75.93;
|
https_ip=8.210.203.112;
|
||||||
https_port=124;
|
https_port=124;
|
||||||
https_del="Host,host,x-online-host";
|
https_del="Host,host,x-online-host";
|
||||||
https_first="[M] [U] [V]\r\nHost: [host]\r\n";
|
https_first="[M] [U] [V]\r\nHost: [host]\r\n";
|
||||||
|
65
http_proxy.c
65
http_proxy.c
@ -91,10 +91,42 @@ static void serverToClient(conn * server)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void clientToserver(conn * in)
|
||||||
|
{
|
||||||
|
int write_len;
|
||||||
|
conn *remote;
|
||||||
|
remote = in + 1;
|
||||||
|
|
||||||
|
write_len = write(remote->fd, in->header_buffer, in->header_buffer_len);
|
||||||
|
if (write_len == in->header_buffer_len) {
|
||||||
|
in->header_buffer_len = 0;
|
||||||
|
in->header_buffer = NULL;
|
||||||
|
} else {
|
||||||
|
close_connection(remote);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// 判断请求类型
|
// 判断请求类型
|
||||||
static int8_t request_type(char *data)
|
static int8_t request_type(char *data)
|
||||||
{
|
{
|
||||||
if (strncmp(data, "GET", 3) == 0 || strncmp(data, "POST", 4) == 0 || strncmp(data, "CONNECT", 7) == 0 || strncmp(data, "HEAD", 4) == 0 || strncmp(data, "PUT", 3) == 0 || strncmp(data, "OPTIONS", 7) == 0 || strncmp(data, "MOVE", 4) == 0 || strncmp(data, "COPY", 4) == 0 || strncmp(data, "TRACE", 5) == 0 || strncmp(data, "DELETE", 6) == 0 || strncmp(data, "LINK", 4) == 0 || strncmp(data, "UNLINK", 6) == 0 || strncmp(data, "PATCH", 5) == 0 || strncmp(data, "WRAPPED", 7) == 0)
|
if (strncmp(data, "GET", 3) == 0 ||
|
||||||
|
strncmp(data, "POST", 4) == 0 ||
|
||||||
|
strncmp(data, "CONNECT", 7) == 0 ||
|
||||||
|
strncmp(data, "HEAD", 4) == 0 ||
|
||||||
|
strncmp(data, "PUT", 3) == 0 ||
|
||||||
|
strncmp(data, "OPTIONS", 7) == 0 ||
|
||||||
|
strncmp(data, "MOVE", 4) == 0 ||
|
||||||
|
strncmp(data, "COPY", 4) == 0 ||
|
||||||
|
strncmp(data, "TRACE", 5) == 0 ||
|
||||||
|
strncmp(data, "DELETE", 6) == 0 ||
|
||||||
|
strncmp(data, "LINK", 4) == 0 ||
|
||||||
|
strncmp(data, "UNLINK", 6) == 0 ||
|
||||||
|
strncmp(data, "PATCH", 5) == 0 ||
|
||||||
|
strncmp(data, "WRAPPED", 7) == 0)
|
||||||
return HTTP_TYPE;
|
return HTTP_TYPE;
|
||||||
return OTHER_TYPE;
|
return OTHER_TYPE;
|
||||||
}
|
}
|
||||||
@ -111,27 +143,36 @@ void tcp_in(conn * in, conf * configure)
|
|||||||
serverToClient(in);
|
serverToClient(in);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
remote = in + 1;
|
|
||||||
in->timer = (in + 1)->timer = 0;
|
in->timer = (in + 1)->timer = 0;
|
||||||
in->header_buffer = read_data(in, in->header_buffer, &in->header_buffer_len);
|
in->header_buffer = read_data(in, in->header_buffer, &in->header_buffer_len);
|
||||||
if (in->header_buffer == NULL) {
|
if (in->header_buffer == NULL) {
|
||||||
close_connection(in);
|
close_connection(in);
|
||||||
return;
|
return;
|
||||||
} else if (in->header_buffer != NULL) {
|
}
|
||||||
if (request_type(in->header_buffer) == HTTP_TYPE) {
|
|
||||||
in->header_buffer = request_head(in, configure);
|
remote = in + 1;
|
||||||
struct epoll_event epollEvent;
|
if (in->request_type == OTHER_TYPE)
|
||||||
remote->fd = create_connection(remote_host, remote_port);
|
{
|
||||||
epollEvent.events = EPOLLIN | EPOLLOUT | EPOLLET;
|
goto handle_data_complete;
|
||||||
epollEvent.data.ptr = remote;
|
}
|
||||||
epoll_ctl(epollfd, EPOLL_CTL_ADD, remote->fd, &epollEvent);
|
|
||||||
}
|
if (request_type(in->header_buffer) == HTTP_TYPE) {
|
||||||
|
in->header_buffer = request_head(in, configure);
|
||||||
|
struct epoll_event epollEvent;
|
||||||
|
remote->fd = create_connection(remote_host, remote_port);
|
||||||
|
epollEvent.events = EPOLLIN | EPOLLOUT | EPOLLET;
|
||||||
|
epollEvent.data.ptr = remote;
|
||||||
|
epoll_ctl(epollfd, EPOLL_CTL_ADD, remote->fd, &epollEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
dataEncode(in->header_buffer, in->header_buffer_len);
|
dataEncode(in->header_buffer, in->header_buffer_len);
|
||||||
|
|
||||||
if (remote->fd >= 0)
|
handle_data_complete:
|
||||||
|
if (remote->fd >= 0) {
|
||||||
|
//clientToserver(in);
|
||||||
tcp_out(remote);
|
tcp_out(remote);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -367,10 +367,10 @@ char *request_head(conn * in, conf * configure)
|
|||||||
in->header_buffer_len = strlen(in->header_buffer);
|
in->header_buffer_len = strlen(in->header_buffer);
|
||||||
free(incomplete_head);
|
free(incomplete_head);
|
||||||
|
|
||||||
} else if (strncmp(in->header_buffer, "GET", 3) == 0) {
|
} else if (strncmp(in->header_buffer, "GET", 3) == 0 || strncmp(in->header_buffer, "POST", 4) == 0) {
|
||||||
char *incomplete_head;
|
char *incomplete_head;
|
||||||
int incomplete_head_len;
|
int incomplete_head_len;
|
||||||
char https_del_copy[configure->http_del_len];
|
char http_del_copy[configure->http_del_len];
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
|
|
||||||
if (configure->http_port > 0)
|
if (configure->http_port > 0)
|
||||||
@ -384,9 +384,9 @@ char *request_head(conn * in, conf * configure)
|
|||||||
}
|
}
|
||||||
memset(incomplete_head, 0, sizeof(char) * (BUFFER_SIZE));
|
memset(incomplete_head, 0, sizeof(char) * (BUFFER_SIZE));
|
||||||
memcpy(incomplete_head, in->header_buffer, strlen(in->header_buffer));
|
memcpy(incomplete_head, in->header_buffer, strlen(in->header_buffer));
|
||||||
memcpy(https_del_copy, configure->https_del, configure->https_del_len);
|
memcpy(http_del_copy, configure->http_del, configure->http_del_len);
|
||||||
|
|
||||||
result = strtok(https_del_copy, ",");
|
result = strtok(http_del_copy, ",");
|
||||||
while (result != NULL) {
|
while (result != NULL) {
|
||||||
delete_head(incomplete_head, result, '\n');
|
delete_head(incomplete_head, result, '\n');
|
||||||
result = strtok(NULL, ",");
|
result = strtok(NULL, ",");
|
||||||
|
Loading…
Reference in New Issue
Block a user