Finally remove compression from proxy
This commit is contained in:
@ -11,7 +11,6 @@
|
||||
#include "../logger.h"
|
||||
#include "proxy.h"
|
||||
#include "utils.h"
|
||||
#include "compress.h"
|
||||
#include "config.h"
|
||||
#include "error.h"
|
||||
|
||||
@ -381,9 +380,8 @@ int proxy_init(proxy_ctx_t **proxy_ptr, http_req *req, http_res *res, http_statu
|
||||
SSL_set_fd(proxy->proxy.ssl, proxy->proxy.socket);
|
||||
SSL_set_connect_state(proxy->proxy.ssl);
|
||||
|
||||
ret = SSL_do_handshake(proxy->proxy.ssl);
|
||||
if (ret != 1) {
|
||||
sock_error(&proxy->proxy, ret);
|
||||
if ((ret = SSL_do_handshake(proxy->proxy.ssl)) != 1) {
|
||||
sock_error(&proxy->proxy, (int) ret);
|
||||
SSL_free(proxy->proxy.ssl);
|
||||
res->status = http_get_status(502);
|
||||
ctx->origin = SERVER_REQ;
|
||||
@ -567,24 +565,8 @@ int proxy_init(proxy_ctx_t **proxy_ptr, http_req *req, http_res *res, http_statu
|
||||
}
|
||||
|
||||
int proxy_send(proxy_ctx_t *proxy, sock *client, unsigned long len_to_send, int flags) {
|
||||
char buffer[CHUNK_SIZE], comp_out[CHUNK_SIZE], buf[256], *ptr;
|
||||
char buffer[CHUNK_SIZE], buf[256], *ptr;
|
||||
long ret = 0, len, snd_len;
|
||||
int finish_comp = 0;
|
||||
|
||||
compress_ctx comp_ctx;
|
||||
if (flags & PROXY_COMPRESS_BR) {
|
||||
flags &= ~PROXY_COMPRESS_GZ;
|
||||
if (compress_init(&comp_ctx, COMPRESS_BR) != 0) {
|
||||
error("Unable to init brotli");
|
||||
flags &= ~PROXY_COMPRESS_BR;
|
||||
}
|
||||
} else if (flags & PROXY_COMPRESS_GZ) {
|
||||
flags &= ~PROXY_COMPRESS_BR;
|
||||
if (compress_init(&comp_ctx, COMPRESS_GZ) != 0) {
|
||||
error("Unable to init gzip");
|
||||
flags &= ~PROXY_COMPRESS_GZ;
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
snd_len = 0;
|
||||
@ -601,37 +583,15 @@ int proxy_send(proxy_ctx_t *proxy, sock *client, unsigned long len_to_send, int
|
||||
|
||||
len_to_send = ret;
|
||||
ret = 1;
|
||||
if (len_to_send == 0 && (flags & PROXY_COMPRESS)) {
|
||||
finish_comp = 1;
|
||||
len = 0;
|
||||
ptr = NULL;
|
||||
goto out;
|
||||
finish:
|
||||
compress_free(&comp_ctx);
|
||||
}
|
||||
}
|
||||
while (snd_len < len_to_send) {
|
||||
unsigned long avail_in, avail_out;
|
||||
ret = sock_recv(&proxy->proxy, buffer, CHUNK_SIZE < (len_to_send - snd_len) ? CHUNK_SIZE : len_to_send - snd_len, 0);
|
||||
if (ret <= 0) {
|
||||
error("Unable to receive from server");
|
||||
break;
|
||||
}
|
||||
len = ret;
|
||||
ptr = buffer;
|
||||
out:
|
||||
avail_in = len;
|
||||
char *next_in = ptr;
|
||||
do {
|
||||
long buf_len = len;
|
||||
if (flags & PROXY_COMPRESS) {
|
||||
avail_out = sizeof(comp_out);
|
||||
compress_compress(&comp_ctx, next_in + len - avail_in, &avail_in, comp_out, &avail_out, finish_comp);
|
||||
ptr = comp_out;
|
||||
buf_len = (int) (sizeof(comp_out) - avail_out);
|
||||
snd_len += (long) (len - avail_in);
|
||||
}
|
||||
if (buf_len != 0) {
|
||||
long buf_len = ret;
|
||||
len = sprintf(buf, "%lX\r\n", buf_len);
|
||||
ret = 1;
|
||||
|
||||
@ -640,7 +600,7 @@ int proxy_send(proxy_ctx_t *proxy, sock *client, unsigned long len_to_send, int
|
||||
|
||||
ret = sock_send_x(client, ptr, buf_len, 0);
|
||||
if (ret <= 0) goto err;
|
||||
if (!(flags & PROXY_COMPRESS)) snd_len += ret;
|
||||
snd_len += ret;
|
||||
|
||||
if (flags & PROXY_CHUNKED) ret = sock_send_x(client, "\r\n", 2, 0);
|
||||
if (ret <= 0) {
|
||||
@ -649,10 +609,6 @@ int proxy_send(proxy_ctx_t *proxy, sock *client, unsigned long len_to_send, int
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while ((flags & PROXY_COMPRESS) && (avail_in != 0 || avail_out != sizeof(comp_out)));
|
||||
if (ret <= 0) break;
|
||||
if (finish_comp) goto finish;
|
||||
}
|
||||
if (ret <= 0) break;
|
||||
if (flags & PROXY_CHUNKED) sock_recv_x(&proxy->proxy, buffer, 2, 0);
|
||||
} while ((flags & PROXY_CHUNKED) && len_to_send > 0);
|
||||
@ -660,8 +616,7 @@ int proxy_send(proxy_ctx_t *proxy, sock *client, unsigned long len_to_send, int
|
||||
if (ret <= 0) return -1;
|
||||
|
||||
if (flags & PROXY_CHUNKED) {
|
||||
ret = sock_send_x(client, "0\r\n\r\n", 5, 0);
|
||||
if (ret <= 0) {
|
||||
if (sock_send_x(client, "0\r\n\r\n", 5, 0) == -1) {
|
||||
error("Unable to send");
|
||||
return -1;
|
||||
}
|
||||
|
@ -10,9 +10,6 @@
|
||||
#define SESIMOS_PROXY_H
|
||||
|
||||
#define PROXY_CHUNKED 1
|
||||
#define PROXY_COMPRESS_GZ 2
|
||||
#define PROXY_COMPRESS_BR 4
|
||||
#define PROXY_COMPRESS 6
|
||||
|
||||
#ifndef SERVER_NAME
|
||||
# define SERVER_NAME "reverse proxy"
|
||||
|
@ -104,35 +104,7 @@ static int proxy_handler_1(client_ctx_t *ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
if (streq(ctx->req.method, "HEAD")) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
char *content_encoding = http_get_header_field(&res->hdr, "Content-Encoding");
|
||||
if (use_proxy && content_encoding == NULL) {
|
||||
int http_comp = http_get_compression(&req, &res);
|
||||
if (http_comp & COMPRESS_BR) {
|
||||
use_proxy |= PROXY_COMPRESS_BR;
|
||||
} else if (http_comp & COMPRESS_GZ) {
|
||||
use_proxy |= PROXY_COMPRESS_GZ;
|
||||
}
|
||||
}
|
||||
|
||||
char *transfer_encoding = http_get_header_field(&res->hdr, "Transfer-Encoding");
|
||||
int chunked = transfer_encoding != NULL && streq(transfer_encoding, "chunked");
|
||||
http_remove_header_field(&res->hdr, "Transfer-Encoding", HTTP_REMOVE_ALL);
|
||||
ret = sprintf(buf, "%s%s%s",
|
||||
(use_proxy & PROXY_COMPRESS_BR) ? "br" :
|
||||
((use_proxy & PROXY_COMPRESS_GZ) ? "gzip" : ""),
|
||||
((use_proxy & PROXY_COMPRESS) && chunked) ? ", " : "",
|
||||
chunked ? "chunked" : "");
|
||||
if (ret > 0) {
|
||||
http_add_header_field(&res->hdr, "Transfer-Encoding", buf);
|
||||
}
|
||||
*/
|
||||
|
||||
return 0;
|
||||
return streq(ctx->req.method, "HEAD") ? 1 : 0;
|
||||
}
|
||||
|
||||
static int proxy_handler_2(client_ctx_t *ctx) {
|
||||
@ -140,12 +112,9 @@ static int proxy_handler_2(client_ctx_t *ctx) {
|
||||
int chunked = strcontains(transfer_encoding, "chunked");
|
||||
|
||||
const char *content_len = http_get_header_field(&ctx->res.hdr, "Content-Length");
|
||||
unsigned long len_to_send = 0;
|
||||
if (content_len != NULL) {
|
||||
len_to_send = strtol(content_len, NULL, 10);
|
||||
}
|
||||
unsigned long len_to_send = (content_len != NULL) ? strtol(content_len, NULL, 10) : 0;
|
||||
|
||||
int flags = (chunked ? PROXY_CHUNKED : 0) | (ctx->use_proxy & PROXY_COMPRESS);
|
||||
int flags = (chunked ? PROXY_CHUNKED : 0);
|
||||
int ret = proxy_send(ctx->proxy, &ctx->socket, len_to_send, flags);
|
||||
|
||||
if (ret < 0) {
|
||||
|
Reference in New Issue
Block a user