Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.

Commit 9e88c3a

Browse files
committed
** DEBUG DO NOT MERGE **
1 parent 284709f commit 9e88c3a

File tree

8 files changed

+120
-0
lines changed

8 files changed

+120
-0
lines changed

src/nxt_brotli.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
*
33
*/
44

5+
#define _GNU_SOURCE
6+
#include <unistd.h>
7+
8+
59
#include <stddef.h>
610
#include <stdint.h>
711
#include <stdbool.h>
@@ -18,6 +22,9 @@ nxt_brotli_init(nxt_http_comp_compressor_ctx_t *ctx)
1822

1923
*brotli = BrotliEncoderCreateInstance(NULL, NULL, NULL);
2024
BrotliEncoderSetParameter(*brotli, BROTLI_PARAM_QUALITY, ctx->level);
25+
26+
printf("%7d %s: brotli compression level [%d]\n", gettid(), __func__,
27+
ctx->level);
2128
}
2229

2330

@@ -36,6 +43,10 @@ nxt_brotli_compress(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf,
3643
size_t out_bytes = out_len;
3744
BrotliEncoderState *brotli = ctx->brotli_ctx;
3845

46+
printf("%7d %s: last/%s\n", gettid(), __func__, last ? "true" : "false");
47+
printf("%7d %s: in_len [%lu] out_len [%lu]\n", gettid(), __func__,
48+
in_len, out_len);
49+
3950
ok = BrotliEncoderCompressStream(brotli, BROTLI_OPERATION_PROCESS,
4051
&in_len, &in_buf, &out_bytes, &out_buf,
4152
NULL);
@@ -44,13 +55,18 @@ nxt_brotli_compress(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf,
4455
&in_len, &in_buf, &out_bytes, &out_buf,
4556
NULL);
4657

58+
printf("%7d %s: in_len [%lu] out_len [%lu] out_bytes [%lu]\n", gettid(),
59+
__func__, in_len, out_len, out_bytes);
4760
if (last) {
4861
ok = BrotliEncoderCompressStream(brotli, BROTLI_OPERATION_FINISH,
4962
&in_len, &in_buf, &out_bytes,
5063
&out_buf, NULL);
5164
BrotliEncoderDestroyInstance(brotli);
5265
}
5366

67+
printf("%7d %s: in_len [%lu] out_len [%lu] out_bytes [%lu]\n", gettid(),
68+
__func__, in_len, out_len, out_bytes);
69+
5470
return out_len - out_bytes;
5571
}
5672

src/nxt_http_compression.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,25 @@ static const nxt_http_comp_type_t compressors[] = {
133133
};
134134

135135

136+
static void print_compressor(const nxt_http_comp_compressor_t *c)
137+
{
138+
printf("token : %s\n", c->type->token.start);
139+
printf("scheme : %d\n", c->type->scheme);
140+
printf("level : %d\n", c->opts.level);
141+
printf("min_len : %ld\n", c->opts.min_len);
142+
}
143+
144+
static void print_comp_config(size_t n)
145+
{
146+
for (size_t i = 0; i < n; i++) {
147+
nxt_http_comp_compressor_t *compr = enabled_compressors + i;
148+
149+
print_compressor(compr);
150+
printf("\n");
151+
}
152+
}
153+
154+
136155
static ssize_t
137156
nxt_http_comp_compress(uint8_t *dst, size_t dst_size, const uint8_t *src,
138157
size_t src_size, bool last)
@@ -172,7 +191,11 @@ nxt_http_comp_compress_app_response(nxt_http_request_t *r, nxt_buf_t **b)
172191
// nxt_buf_t *buf;
173192
nxt_http_comp_ctx_t *ctx = &compressor_ctx;
174193

194+
printf("%s: \n", __func__);
195+
175196
if (ctx->idx == NXT_HTTP_COMP_SCHEME_IDENTITY) {
197+
printf("%s: NXT_HTTP_COMP_SCHEME_IDENTITY [skipping/identity]\n",
198+
__func__);
176199
return NXT_OK;
177200
}
178201

@@ -185,14 +208,19 @@ nxt_http_comp_compress_app_response(nxt_http_request_t *r, nxt_buf_t **b)
185208
in_len = (*b)->mem.free - (*b)->mem.pos;
186209
buf_len = nxt_http_comp_bound(in_len);
187210

211+
printf("%s: in_len [%lu] buf_len [%lu] last [%s]\n", __func__,
212+
in_len, buf_len, last ? "true" : "false");
213+
188214
#if 1
189215
if (buf_len > (size_t)nxt_buf_mem_size(&(*b)->mem)) {
216+
/* XXX Un-skip Content-Length header, or not... */
190217
return NXT_OK;
191218
}
192219

193220
uint8_t *buf = nxt_malloc(buf_len);
194221

195222
cbytes = nxt_http_comp_compress(buf, buf_len, (*b)->mem.pos, in_len, last);
223+
printf("%s: cbytes = %ld\n", __func__, cbytes);
196224
if (cbytes == -1) {
197225
nxt_free(buf);
198226
return NXT_ERROR;
@@ -307,8 +335,12 @@ nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f,
307335

308336
last = n == rest;
309337

338+
printf("%s: out_off [%ld] in_off [%ld] last [%s]\n",
339+
__func__, *out_total, in_size - rest, last ? "true" : "false");
340+
310341
cbytes = nxt_http_comp_compress(out + *out_total, out_size - *out_total,
311342
in + in_size - rest, n, last);
343+
printf("%s: cbytes [%ld]\n", __func__, cbytes);
312344

313345
*out_total += cbytes;
314346
rest -= n;
@@ -337,6 +369,8 @@ nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f,
337369
bool
338370
nxt_http_comp_wants_compression(void)
339371
{
372+
printf("%s: compression [%s]\n", __func__,
373+
compressor_ctx.idx > 0 ? "true" : "false");
340374
return compressor_ctx.idx;
341375
}
342376

@@ -425,6 +459,9 @@ nxt_http_comp_select_compressor(nxt_http_request_t *r, const nxt_str_t *token)
425459

426460
scheme = enabled_compressors[ecidx].type->scheme;
427461

462+
printf("%s: %.*s [%f] [%d:%d]\n", __func__, (int)enc.length, enc.start,
463+
qval, ecidx, scheme);
464+
428465
if (qval == 0.0 && scheme == NXT_HTTP_COMP_SCHEME_IDENTITY) {
429466
identity_allowed = false;
430467
}
@@ -437,6 +474,12 @@ nxt_http_comp_select_compressor(nxt_http_request_t *r, const nxt_str_t *token)
437474
weight = qval;
438475
}
439476

477+
printf("%s: Selected compressor : %s\n", __func__,
478+
enabled_compressors[idx].type->token.start);
479+
480+
printf("%s: idx [%u], identity_allowed [%s]\n", __func__, idx,
481+
identity_allowed ? "true" : "false");
482+
440483
if (idx == NXT_HTTP_COMP_SCHEME_IDENTITY && !identity_allowed) {
441484
return -1;
442485
}
@@ -454,6 +497,14 @@ nxt_http_comp_set_header(nxt_http_request_t *r, nxt_uint_t comp_idx)
454497
static const nxt_str_t content_encoding_str =
455498
nxt_string("Content-Encoding");
456499

500+
printf("%s: \n", __func__);
501+
502+
#if 0
503+
if (comp_idx == NXT_HTTP_COMP_SCHEME_IDENTITY) {
504+
return NXT_OK;
505+
}
506+
#endif
507+
457508
f = nxt_list_add(r->resp.fields);
458509
if (nxt_slow_path(f == NULL)) {
459510
return NXT_ERROR;
@@ -482,6 +533,8 @@ nxt_http_comp_set_header(nxt_http_request_t *r, nxt_uint_t comp_idx)
482533
if (nxt_strcasecmp(f->name,
483534
(const u_char *)"Content-Length") == 0)
484535
{
536+
printf("%s: Found (%s: %s), marking as 'skip'\n", __func__,
537+
f->name, f->value);
485538
f->skip = true;
486539
break;
487540
}
@@ -497,7 +550,11 @@ nxt_http_comp_is_resp_content_encoded(const nxt_http_request_t *r)
497550
{
498551
nxt_http_field_t *f;
499552

553+
printf("%s: \n", __func__);
554+
500555
nxt_list_each(f, r->resp.fields) {
556+
printf("%s: %.*s: %.*s\n", __func__, f->name_length, f->name,
557+
f->value_length, f->value);
501558
if (nxt_strcasecmp(f->name, (const u_char *)"Content-Encoding") == 0) {
502559
return true;
503560
}
@@ -516,6 +573,8 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r)
516573
nxt_router_conf_t *rtcf;
517574
nxt_http_comp_compressor_t *compressor;
518575

576+
printf("%s: \n", __func__);
577+
519578
compressor_ctx = (nxt_http_comp_ctx_t){ .resp_clen = -1 };
520579

521580
if (nr_enabled_compressors == 0) {
@@ -537,10 +596,15 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r)
537596
return NXT_OK;
538597
}
539598

599+
printf("%s: Response Content-Type [%.*s]\n", __func__,
600+
(int)mime_type.length, mime_type.start);
601+
540602
if (mime_types_rule != NULL) {
541603
ret = nxt_http_route_test_rule(r, mime_types_rule,
542604
mime_type.start,
543605
mime_type.length);
606+
printf("%s: mime_type : %d (%.*s)\n", __func__, ret,
607+
(int)mime_type.length, mime_type.start);
544608
if (ret == 0) {
545609
return NXT_OK;
546610
}
@@ -589,7 +653,11 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r)
589653

590654
min_len = compressor->opts.min_len;
591655

656+
printf("%s: content_length [%ld] min_len [%ld]\n", __func__,
657+
compressor_ctx.resp_clen, min_len);
592658
if (compressor_ctx.resp_clen > -1 && compressor_ctx.resp_clen < min_len) {
659+
printf("%s: %ld < %ld [skipping/clen]\n", __func__,
660+
compressor_ctx.resp_clen , min_len);
593661
return NXT_OK;
594662
}
595663

@@ -643,6 +711,8 @@ nxt_http_comp_set_compressor(nxt_task_t *task, nxt_router_conf_t *rtcf,
643711

644712
static const nxt_str_t token_str = nxt_string("encoding");
645713

714+
printf("%s: \n", __func__);
715+
646716
obj = nxt_conf_get_object_member(comp, &token_str, NULL);
647717
if (obj == NULL) {
648718
return NXT_ERROR;
@@ -656,6 +726,7 @@ nxt_http_comp_set_compressor(nxt_task_t *task, nxt_router_conf_t *rtcf,
656726
compr->type = &compressors[cidx];
657727
compr->opts.level = compr->type->def_compr;
658728
compr->opts.min_len = -1;
729+
printf("%s: %s\n", __func__, compr->type->token.start);
659730

660731
ret = nxt_conf_map_object(rtcf->mem_pool, comp, compressors_opts_map,
661732
nxt_nitems(compressors_opts_map), &compr->opts);
@@ -690,6 +761,8 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
690761
static const nxt_str_t comps_str = nxt_string("compressors");
691762
static const nxt_str_t mimes_str = nxt_string("types");
692763

764+
printf("%s: \n", __func__);
765+
693766
mimes = nxt_conf_get_object_member(comp_conf, &mimes_str, NULL);
694767
if (mimes != NULL) {
695768
mime_types_rule = nxt_http_route_types_rule_create(task,
@@ -727,6 +800,7 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
727800
.opts.min_len = -1 };
728801

729802
if (nxt_conf_type(comps) == NXT_CONF_OBJECT) {
803+
print_comp_config(nr_enabled_compressors);
730804
return nxt_http_comp_set_compressor(task, rtcf, comps, 1);
731805
}
732806

@@ -740,5 +814,7 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
740814
}
741815
}
742816

817+
print_comp_config(nr_enabled_compressors);
818+
743819
return NXT_OK;
744820
}

src/nxt_http_request.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ nxt_http_request_start(nxt_task_t *task, void *obj, void *data)
320320
nxt_socket_conf_t *skcf;
321321
nxt_http_request_t *r;
322322

323+
printf("%s: \n", __func__);
324+
323325
r = obj;
324326

325327
NXT_OTEL_TRACE();
@@ -692,6 +694,8 @@ nxt_http_request_header_send(nxt_task_t *task, nxt_http_request_t *r,
692694
nxt_http_field_t *server, *date, *content_length;
693695
nxt_socket_conf_t *skcf;
694696

697+
printf("%s: \n", __func__);
698+
695699
ret = nxt_http_set_headers(r);
696700
if (nxt_slow_path(ret != NXT_OK)) {
697701
goto fail;
@@ -783,6 +787,9 @@ void
783787
nxt_http_request_send(nxt_task_t *task, nxt_http_request_t *r, nxt_buf_t *out)
784788
{
785789
if (nxt_fast_path(r->proto.any != NULL)) {
790+
printf("%s: sending [%lu] bytes\n", __func__,
791+
nxt_buf_mem_used_size(&out->mem));
792+
786793
nxt_http_proto[r->protocol].send(task, r, out);
787794
}
788795
}

src/nxt_http_route.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,8 @@ nxt_http_action_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
688688
nxt_router_conf_t *rtcf;
689689
nxt_http_action_conf_t acf;
690690

691+
printf("%s: \n", __func__);
692+
691693
nxt_memzero(&acf, sizeof(acf));
692694

693695
ret = nxt_conf_map_object(tmcf->mem_pool, cv, nxt_http_route_action_conf,

src/nxt_http_static.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ nxt_http_static_send(nxt_task_t *task, nxt_http_request_t *r,
327327
nxt_work_handler_t body_handler;
328328
nxt_http_static_conf_t *conf;
329329

330+
printf("%s: \n", __func__);
331+
330332
action = ctx->action;
331333
conf = action->u.conf;
332334
rtcf = r->conf->socket_conf->router_conf;
@@ -821,6 +823,8 @@ nxt_http_static_body_handler(nxt_task_t *task, void *obj, void *data)
821823
nxt_work_queue_t *wq;
822824
nxt_http_request_t *r;
823825

826+
printf("%s: \n", __func__);
827+
824828
r = obj;
825829
fb = r->out;
826830

@@ -881,6 +885,8 @@ nxt_http_static_buf_completion(nxt_task_t *task, void *obj, void *data)
881885
nxt_off_t rest;
882886
nxt_http_request_t *r;
883887

888+
printf("%s: \n", __func__);
889+
884890
b = obj;
885891
r = data;
886892

src/nxt_router.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4136,6 +4136,8 @@ nxt_router_response_ready_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg,
41364136
nxt_unit_response_t *resp;
41374137
nxt_request_rpc_data_t *req_rpc_data;
41384138

4139+
printf("%s: \n", __func__);
4140+
41394141
req_rpc_data = data;
41404142

41414143
r = req_rpc_data->request;

src/nxt_zlib.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ nxt_zlib_deflate(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf,
5959
z->avail_out = out_len;
6060
z->next_out = out_buf;
6161

62+
printf("%s: in_len [%lu], out_len [%lu]\n", __func__, in_len, out_len);
63+
6264
compressed_bytes = z->total_out;
6365

6466
ret = deflate(z, last ? Z_FINISH : Z_SYNC_FLUSH);
6567
if (ret == Z_STREAM_ERROR || ret == Z_BUF_ERROR) {
6668
deflateEnd(z);
69+
printf("%s: ret = %d\n", __func__, ret);
6770
return -1;
6871
}
6972

src/nxt_zstd.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ nxt_zstd_init(nxt_http_comp_compressor_ctx_t *ctx)
1818

1919
*zstd = ZSTD_createCStream();
2020
ZSTD_initCStream(*zstd, ctx->level);
21+
22+
printf("%s: zstd compression level [%d]\n", __func__, ctx->level);
2123
}
2224

2325

@@ -37,9 +39,13 @@ nxt_zstd_compress(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf,
3739
ZSTD_inBuffer zinb = { .src = in_buf, .size = in_len };
3840
ZSTD_outBuffer zoutb = { .dst = out_buf, .size = out_len };
3941

42+
printf("%s: in_len [%lu] out_len [%lu] last [%s]\n", __func__,
43+
in_len, out_len, last ? "true" : "false");
44+
4045
ret = ZSTD_compressStream(zstd, &zoutb, &zinb);
4146

4247
if (zinb.pos < zinb.size) {
48+
printf("%s: short by [%d]\n", __func__, zinb.pos < zinb.size);
4349
ret = ZSTD_flushStream(zstd, &zoutb);
4450
}
4551

@@ -48,7 +54,9 @@ nxt_zstd_compress(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf,
4854
ZSTD_freeCStream(zstd);
4955
}
5056

57+
printf("%s: ret [%lu]\n", __func__, ret);
5158
if (ZSTD_isError(ret)) {
59+
printf("%s: [%s]\n", __func__, ZSTD_getErrorName(ret));
5260
return -1;
5361
}
5462

0 commit comments

Comments
 (0)