Skip to content

A couple of HTTP compression fixes #1632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/nxt_http_compression.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,12 @@ nxt_http_comp_compress_app_response(nxt_task_t *task, nxt_http_request_t *r,


nxt_int_t
nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f,
nxt_file_info_t *fi,
size_t static_buf_len,
size_t *out_total)
nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_http_request_t *r,
nxt_file_t **f, nxt_file_info_t *fi,
size_t static_buf_len, size_t *out_total)
{
char tmp_path[NXT_MAX_PATH_LEN];
size_t in_size, out_size, rest;
u_char *p;
char *tmp_path, *p;
uint8_t *in, *out;
nxt_int_t ret;
nxt_file_t tfile;
Expand All @@ -249,13 +247,14 @@ nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f,

*out_total = 0;

if (nxt_slow_path(strlen(rt->tmp) + 1 + strlen(template) + 1
> NXT_MAX_PATH_LEN))
{
tmp_path = nxt_mp_nget(r->mem_pool,
strlen(rt->tmp) + 1 + strlen(template) + 1);
if (nxt_slow_path(tmp_path == NULL)) {
return NXT_ERROR;
}

p = nxt_cpymem(tmp_path, rt->tmp, strlen(rt->tmp));
p = tmp_path;
p = nxt_cpymem(p, rt->tmp, strlen(rt->tmp));
*p++ = '/';
p = nxt_cpymem(p, template, strlen(template));
*p = '\0';
Expand All @@ -266,6 +265,7 @@ nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f,
return NXT_ERROR;
}
unlink(tmp_path);
tfile.name = (nxt_file_name_t *)tmp_path;

in_size = nxt_file_size(fi);
out_size = nxt_http_comp_bound(in_size);
Expand Down Expand Up @@ -305,6 +305,12 @@ nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f,

cbytes = nxt_http_comp_compress(out + *out_total, out_size - *out_total,
in + in_size - rest, n, last);
if (cbytes == -1) {
nxt_file_close(task, &tfile);
nxt_mem_munmap(in, in_size);
nxt_mem_munmap(out, out_size);
return NXT_ERROR;
}

*out_total += cbytes;
rest -= n;
Expand Down
4 changes: 2 additions & 2 deletions src/nxt_http_compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ extern const nxt_http_comp_operations_t nxt_http_comp_brotli_ops;
extern nxt_int_t nxt_http_comp_compress_app_response(nxt_task_t *task,
nxt_http_request_t *r, nxt_buf_t **b);
extern nxt_int_t nxt_http_comp_compress_static_response(nxt_task_t *task,
nxt_file_t **f, nxt_file_info_t *fi, size_t static_buf_len,
size_t *out_total);
nxt_http_request_t *r, nxt_file_t **f, nxt_file_info_t *fi,
size_t static_buf_len, size_t *out_total);
extern bool nxt_http_comp_wants_compression(void);
extern bool nxt_http_comp_compressor_is_valid(const nxt_str_t *token);
extern nxt_int_t nxt_http_comp_check_compression(nxt_task_t *task,
Expand Down
2 changes: 1 addition & 1 deletion src/nxt_http_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ nxt_http_static_send(nxt_task_t *task, nxt_http_request_t *r,
nxt_int_t ret;

ret = nxt_http_comp_compress_static_response(
task, &f, &fi,
task, r, &f, &fi,
NXT_HTTP_STATIC_BUF_SIZE,
&out_total);
if (ret == NXT_ERROR) {
Expand Down