Remove client buffer
This commit is contained in:
@ -720,12 +720,6 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int
|
||||
}
|
||||
http_free_req(&req);
|
||||
http_free_res(&res);
|
||||
if (client->buf != NULL) {
|
||||
free(client->buf);
|
||||
client->buf = NULL;
|
||||
client->buf_off = 0;
|
||||
client->buf_len = 0;
|
||||
}
|
||||
return !client_keep_alive;
|
||||
}
|
||||
|
||||
|
@ -600,12 +600,6 @@ int fastcgi_receive(fastcgi_conn *conn, sock *client, unsigned long len) {
|
||||
.reserved = 0
|
||||
};
|
||||
|
||||
if (client->buf != NULL && client->buf_len - client->buf_off > 0) {
|
||||
ret = (int) (client->buf_len - client->buf_off);
|
||||
memcpy(buf, client->buf + client->buf_off, ret);
|
||||
goto send;
|
||||
}
|
||||
|
||||
while (rcv_len < len) {
|
||||
ret = sock_recv(client, buf, sizeof(buf), 0);
|
||||
if (ret <= 0) {
|
||||
@ -613,7 +607,6 @@ int fastcgi_receive(fastcgi_conn *conn, sock *client, unsigned long len) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
send:
|
||||
rcv_len += ret;
|
||||
header.contentLengthB1 = (ret >> 8) & 0xFF;
|
||||
header.contentLengthB0 = ret & 0xFF;
|
||||
|
@ -145,7 +145,7 @@ int http_receive_request(sock *client, http_req *req) {
|
||||
req->hdr.last_field_num = -1;
|
||||
|
||||
while (1) {
|
||||
rcv_len = sock_recv(client, buf, CLIENT_MAX_HEADER_SIZE, 0);
|
||||
rcv_len = sock_recv(client, buf, CLIENT_MAX_HEADER_SIZE, MSG_PEEK);
|
||||
if (rcv_len <= 0) {
|
||||
print("Unable to receive http header: %s", sock_strerror(client));
|
||||
return -1;
|
||||
@ -155,6 +155,8 @@ int http_receive_request(sock *client, http_req *req) {
|
||||
if (header_len <= 0) {
|
||||
print(ERR_STR "Unable to parse http header: End of header not found" CLR_STR);
|
||||
return 5;
|
||||
} else {
|
||||
rcv_len = sock_recv(client, buf, header_len, 0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < header_len; i++) {
|
||||
@ -216,13 +218,6 @@ int http_receive_request(sock *client, http_req *req) {
|
||||
}
|
||||
}
|
||||
|
||||
client->buf_len = rcv_len - (pos0 - buf + 4);
|
||||
if (client->buf_len > 0) {
|
||||
client->buf = malloc(client->buf_len);
|
||||
client->buf_off = 0;
|
||||
memcpy(client->buf, pos0 + 4, client->buf_len);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -25,9 +25,6 @@ char *rev_proxy_host = NULL;
|
||||
struct timeval server_timeout = {.tv_sec = SERVER_TIMEOUT, .tv_usec = 0};
|
||||
|
||||
int rev_proxy_preload(void) {
|
||||
rev_proxy.buf = NULL;
|
||||
rev_proxy.buf_len = 0;
|
||||
rev_proxy.buf_off = 0;
|
||||
rev_proxy.ctx = SSL_CTX_new(TLS_client_method());
|
||||
return 0;
|
||||
}
|
||||
@ -326,30 +323,15 @@ int rev_proxy_init(http_req *req, http_res *res, http_status_ctx *ctx, host_conf
|
||||
const char *content_length = http_get_header_field(&req->hdr, "Content-Length");
|
||||
if (content_length != NULL) {
|
||||
unsigned long content_len = strtoul(content_length, NULL, 10);
|
||||
if (client->buf_len - client->buf_off > 0) {
|
||||
unsigned long len = client->buf_len - client->buf_off;
|
||||
if (len > content_len) {
|
||||
len = content_len;
|
||||
}
|
||||
ret = sock_send(&rev_proxy, client->buf, len, 0);
|
||||
if (ret <= 0) {
|
||||
res->status = http_get_status(502);
|
||||
ctx->origin = SERVER_REQ;
|
||||
print(ERR_STR "Unable to send request to server (2): %s" CLR_STR, sock_strerror(&rev_proxy));
|
||||
sprintf(err_msg, "Unable to send request to server: %s.", sock_strerror(&rev_proxy));
|
||||
retry = tries < 4;
|
||||
goto proxy_err;
|
||||
}
|
||||
content_len -= len;
|
||||
}
|
||||
if (content_len > 0) {
|
||||
ret = sock_splice(&rev_proxy, client, buffer, sizeof(buffer), content_len);
|
||||
if (ret <= 0) {
|
||||
if (ret == -1) {
|
||||
res->status = http_get_status(502);
|
||||
ctx->origin = SERVER_REQ;
|
||||
print(ERR_STR "Unable to send request to server (3): %s" CLR_STR, sock_strerror(&rev_proxy));
|
||||
print(ERR_STR "Unable to send request to server (2): %s" CLR_STR, sock_strerror(&rev_proxy));
|
||||
sprintf(err_msg, "Unable to send request to server: %s.", sock_strerror(&rev_proxy));
|
||||
retry = tries < 4;
|
||||
goto proxy_err;
|
||||
} else if (ret == -2) {
|
||||
res->status = http_get_status(400);
|
||||
|
@ -17,9 +17,6 @@ typedef struct {
|
||||
int socket;
|
||||
SSL_CTX *ctx;
|
||||
SSL *ssl;
|
||||
char *buf;
|
||||
unsigned long buf_len;
|
||||
unsigned long buf_off;
|
||||
long _last_ret;
|
||||
int _errno;
|
||||
unsigned long _ssl_error;
|
||||
|
@ -291,10 +291,6 @@ int main(int argc, const char *argv[]) {
|
||||
|
||||
openssl_init();
|
||||
|
||||
client.buf = NULL;
|
||||
client.buf_len = 0;
|
||||
client.buf_off = 0;
|
||||
|
||||
for (int i = 0; i < CONFIG_MAX_CERT_CONFIG; i++) {
|
||||
const cert_config *conf = &config->certs[i];
|
||||
if (conf->name[0] == 0) break;
|
||||
|
Reference in New Issue
Block a user