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

Commit 753e792

Browse files
committed
** DEBUG DO NOT MERGE **
1 parent ea1f708 commit 753e792

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
@@ -3,6 +3,10 @@
33
* Copyright (C) F5, Inc.
44
*/
55

6+
#define _GNU_SOURCE
7+
#include <unistd.h>
8+
9+
610
#include <stddef.h>
711
#include <stdint.h>
812
#include <stdbool.h>
@@ -23,6 +27,9 @@ nxt_brotli_init(nxt_http_comp_compressor_ctx_t *ctx)
2327
}
2428
BrotliEncoderSetParameter(*brotli, BROTLI_PARAM_QUALITY, ctx->level);
2529

30+
printf("%7d %s: brotli compression level [%d]\n", gettid(), __func__,
31+
ctx->level);
32+
2633
return 0;
2734
}
2835

@@ -42,6 +49,10 @@ nxt_brotli_compress(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf,
4249
size_t out_bytes = out_len;
4350
BrotliEncoderState *brotli = ctx->brotli_ctx;
4451

52+
printf("%7d %s: last/%s\n", gettid(), __func__, last ? "true" : "false");
53+
printf("%7d %s: in_len [%lu] out_len [%lu]\n", gettid(), __func__,
54+
in_len, out_len);
55+
4556
ok = BrotliEncoderCompressStream(brotli, BROTLI_OPERATION_PROCESS,
4657
&in_len, &in_buf, &out_bytes, &out_buf,
4758
NULL);
@@ -56,6 +67,8 @@ nxt_brotli_compress(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf,
5667
return -1;
5768
}
5869

70+
printf("%7d %s: in_len [%lu] out_len [%lu] out_bytes [%lu]\n", gettid(),
71+
__func__, in_len, out_len, out_bytes);
5972
if (last) {
6073
ok = BrotliEncoderCompressStream(brotli, BROTLI_OPERATION_FINISH,
6174
&in_len, &in_buf, &out_bytes,
@@ -67,6 +80,9 @@ nxt_brotli_compress(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf,
6780
BrotliEncoderDestroyInstance(brotli);
6881
}
6982

83+
printf("%7d %s: in_len [%lu] out_len [%lu] out_bytes [%lu]\n", gettid(),
84+
__func__, in_len, out_len, out_bytes);
85+
7086
return out_len - out_bytes;
7187
}
7288

src/nxt_http_compression.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,26 @@ static const nxt_http_comp_type_t nxt_http_comp_compressors[] = {
137137
};
138138

139139

140+
static void print_compressor(const nxt_http_comp_compressor_t *c)
141+
{
142+
printf("token : %s\n", c->type->token.start);
143+
printf("scheme : %d\n", c->type->scheme);
144+
printf("level : %d\n", c->opts.level);
145+
printf("min_len : %ld\n", c->opts.min_len);
146+
}
147+
148+
static void print_comp_config(size_t n)
149+
{
150+
for (size_t i = 0; i < n; i++) {
151+
nxt_http_comp_compressor_t *compr =
152+
nxt_http_comp_enabled_compressors + i;
153+
154+
print_compressor(compr);
155+
printf("\n");
156+
}
157+
}
158+
159+
140160
static ssize_t
141161
nxt_http_comp_compress(uint8_t *dst, size_t dst_size, const uint8_t *src,
142162
size_t src_size, bool last)
@@ -176,7 +196,11 @@ nxt_http_comp_compress_app_response(nxt_http_request_t *r, nxt_buf_t **b)
176196
// nxt_buf_t *buf;
177197
nxt_http_comp_ctx_t *ctx = nxt_http_comp_ctx();
178198

199+
printf("%s: \n", __func__);
200+
179201
if (ctx->idx == NXT_HTTP_COMP_SCHEME_IDENTITY) {
202+
printf("%s: NXT_HTTP_COMP_SCHEME_IDENTITY [skipping/identity]\n",
203+
__func__);
180204
return NXT_OK;
181205
}
182206

@@ -189,14 +213,19 @@ nxt_http_comp_compress_app_response(nxt_http_request_t *r, nxt_buf_t **b)
189213
in_len = (*b)->mem.free - (*b)->mem.pos;
190214
buf_len = nxt_http_comp_bound(in_len);
191215

216+
printf("%s: in_len [%lu] buf_len [%lu] last [%s]\n", __func__,
217+
in_len, buf_len, last ? "true" : "false");
218+
192219
#if 1
193220
if (buf_len > (size_t)nxt_buf_mem_size(&(*b)->mem)) {
221+
/* XXX Un-skip Content-Length header, or not... */
194222
return NXT_OK;
195223
}
196224

197225
uint8_t *buf = nxt_malloc(buf_len);
198226

199227
cbytes = nxt_http_comp_compress(buf, buf_len, (*b)->mem.pos, in_len, last);
228+
printf("%s: cbytes = %ld\n", __func__, cbytes);
200229
if (cbytes == -1) {
201230
nxt_free(buf);
202231
return NXT_ERROR;
@@ -311,8 +340,12 @@ nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f,
311340

312341
last = n == rest;
313342

343+
printf("%s: out_off [%ld] in_off [%ld] last [%s]\n",
344+
__func__, *out_total, in_size - rest, last ? "true" : "false");
345+
314346
cbytes = nxt_http_comp_compress(out + *out_total, out_size - *out_total,
315347
in + in_size - rest, n, last);
348+
printf("%s: cbytes [%ld]\n", __func__, cbytes);
316349

317350
*out_total += cbytes;
318351
rest -= n;
@@ -343,6 +376,7 @@ nxt_http_comp_wants_compression(void)
343376
{
344377
nxt_http_comp_ctx_t *ctx = nxt_http_comp_ctx();
345378

379+
printf("%s: compression [%s]\n", __func__, ctx->idx > 0 ? "true" : "false");
346380
return ctx->idx;
347381
}
348382

@@ -437,6 +471,9 @@ nxt_http_comp_select_compressor(nxt_http_request_t *r, const nxt_str_t *token)
437471

438472
scheme = nxt_http_comp_enabled_compressors[ecidx].type->scheme;
439473

474+
printf("%s: %.*s [%f] [%d:%d]\n", __func__, (int)enc.length, enc.start,
475+
qval, ecidx, scheme);
476+
440477
if (qval == 0.0 && scheme == NXT_HTTP_COMP_SCHEME_IDENTITY) {
441478
identity_allowed = false;
442479
}
@@ -449,6 +486,12 @@ nxt_http_comp_select_compressor(nxt_http_request_t *r, const nxt_str_t *token)
449486
weight = qval;
450487
}
451488

489+
printf("%s: Selected compressor : %s\n", __func__,
490+
nxt_http_comp_enabled_compressors[idx].type->token.start);
491+
492+
printf("%s: idx [%u], identity_allowed [%s]\n", __func__, idx,
493+
identity_allowed ? "true" : "false");
494+
452495
if (idx == NXT_HTTP_COMP_SCHEME_IDENTITY && !identity_allowed) {
453496
return -1;
454497
}
@@ -466,6 +509,14 @@ nxt_http_comp_set_header(nxt_http_request_t *r, nxt_uint_t comp_idx)
466509
static const nxt_str_t content_encoding_str =
467510
nxt_string("Content-Encoding");
468511

512+
printf("%s: \n", __func__);
513+
514+
#if 0
515+
if (comp_idx == NXT_HTTP_COMP_SCHEME_IDENTITY) {
516+
return NXT_OK;
517+
}
518+
#endif
519+
469520
f = nxt_list_add(r->resp.fields);
470521
if (nxt_slow_path(f == NULL)) {
471522
return NXT_ERROR;
@@ -494,6 +545,8 @@ nxt_http_comp_set_header(nxt_http_request_t *r, nxt_uint_t comp_idx)
494545
if (nxt_strcasecmp(f->name,
495546
(const u_char *)"Content-Length") == 0)
496547
{
548+
printf("%s: Found (%s: %s), marking as 'skip'\n", __func__,
549+
f->name, f->value);
497550
f->skip = true;
498551
break;
499552
}
@@ -509,7 +562,11 @@ nxt_http_comp_is_resp_content_encoded(const nxt_http_request_t *r)
509562
{
510563
nxt_http_field_t *f;
511564

565+
printf("%s: \n", __func__);
566+
512567
nxt_list_each(f, r->resp.fields) {
568+
printf("%s: %.*s: %.*s\n", __func__, f->name_length, f->name,
569+
f->value_length, f->value);
513570
if (nxt_strcasecmp(f->name, (const u_char *)"Content-Encoding") == 0) {
514571
return true;
515572
}
@@ -530,6 +587,8 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r)
530587
nxt_http_comp_ctx_t *ctx = nxt_http_comp_ctx();
531588
nxt_http_comp_compressor_t *compressor;
532589

590+
printf("%s: \n", __func__);
591+
533592
*ctx = (nxt_http_comp_ctx_t){ .resp_clen = -1 };
534593

535594
if (nxt_http_comp_nr_enabled_compressors == 0) {
@@ -551,10 +610,15 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r)
551610
return NXT_OK;
552611
}
553612

613+
printf("%s: Response Content-Type [%.*s]\n", __func__,
614+
(int)mime_type.length, mime_type.start);
615+
554616
if (nxt_http_comp_mime_types_rule != NULL) {
555617
ret = nxt_http_route_test_rule(r, nxt_http_comp_mime_types_rule,
556618
mime_type.start,
557619
mime_type.length);
620+
printf("%s: mime_type : %d (%.*s)\n", __func__, ret,
621+
(int)mime_type.length, mime_type.start);
558622
if (ret == 0) {
559623
return NXT_OK;
560624
}
@@ -599,7 +663,11 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r)
599663

600664
min_len = compressor->opts.min_len;
601665

666+
printf("%s: content_length [%ld] min_len [%ld]\n", __func__,
667+
ctx->resp_clen, min_len);
602668
if (ctx->resp_clen > -1 && ctx->resp_clen < min_len) {
669+
printf("%s: %ld < %ld [skipping/clen]\n", __func__,
670+
ctx->resp_clen, min_len);
603671
return NXT_OK;
604672
}
605673

@@ -656,6 +724,8 @@ nxt_http_comp_set_compressor(nxt_task_t *task, nxt_router_conf_t *rtcf,
656724

657725
static const nxt_str_t token_str = nxt_string("encoding");
658726

727+
printf("%s: \n", __func__);
728+
659729
obj = nxt_conf_get_object_member(comp, &token_str, NULL);
660730
if (obj == NULL) {
661731
return NXT_ERROR;
@@ -669,6 +739,7 @@ nxt_http_comp_set_compressor(nxt_task_t *task, nxt_router_conf_t *rtcf,
669739
compr->type = &nxt_http_comp_compressors[cidx];
670740
compr->opts.level = compr->type->def_compr;
671741
compr->opts.min_len = -1;
742+
printf("%s: %s\n", __func__, compr->type->token.start);
672743

673744
ret = nxt_conf_map_object(rtcf->mem_pool, comp,
674745
nxt_http_comp_compressors_opts_map,
@@ -705,6 +776,8 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
705776
static const nxt_str_t comps_str = nxt_string("compressors");
706777
static const nxt_str_t mimes_str = nxt_string("types");
707778

779+
printf("%s: \n", __func__);
780+
708781
mimes = nxt_conf_get_object_member(comp_conf, &mimes_str, NULL);
709782
if (mimes != NULL) {
710783
nxt_http_comp_mime_types_rule =
@@ -744,6 +817,7 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
744817
.opts.min_len = -1 };
745818

746819
if (nxt_conf_type(comps) == NXT_CONF_OBJECT) {
820+
print_comp_config(nxt_http_comp_nr_enabled_compressors);
747821
return nxt_http_comp_set_compressor(task, rtcf, comps, 1);
748822
}
749823

@@ -757,5 +831,7 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
757831
}
758832
}
759833

834+
print_comp_config(nxt_http_comp_nr_enabled_compressors);
835+
760836
return NXT_OK;
761837
}

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;
@@ -824,6 +826,8 @@ nxt_http_static_body_handler(nxt_task_t *task, void *obj, void *data)
824826
nxt_work_queue_t *wq;
825827
nxt_http_request_t *r;
826828

829+
printf("%s: \n", __func__);
830+
827831
r = obj;
828832
fb = r->out;
829833

@@ -884,6 +888,8 @@ nxt_http_static_buf_completion(nxt_task_t *task, void *obj, void *data)
884888
nxt_off_t rest;
885889
nxt_http_request_t *r;
886890

891+
printf("%s: \n", __func__);
892+
887893
b = obj;
888894
r = data;
889895

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
@@ -58,11 +58,14 @@ nxt_zlib_deflate(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf,
5858
z->avail_out = out_len;
5959
z->next_out = out_buf;
6060

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

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

src/nxt_zstd.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ nxt_zstd_init(nxt_http_comp_compressor_ctx_t *ctx)
2323
}
2424
ZSTD_initCStream(*zstd, ctx->level);
2525

26+
printf("%s: zstd compression level [%d]\n", __func__, ctx->level);
27+
2628
return 0;
2729
}
2830

@@ -43,9 +45,13 @@ nxt_zstd_compress(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf,
4345
ZSTD_inBuffer zinb = { .src = in_buf, .size = in_len };
4446
ZSTD_outBuffer zoutb = { .dst = out_buf, .size = out_len };
4547

48+
printf("%s: in_len [%lu] out_len [%lu] last [%s]\n", __func__,
49+
in_len, out_len, last ? "true" : "false");
50+
4651
ret = ZSTD_compressStream(zstd, &zoutb, &zinb);
4752

4853
if (zinb.pos < zinb.size) {
54+
printf("%s: short by [%d]\n", __func__, zinb.pos < zinb.size);
4955
ret = ZSTD_flushStream(zstd, &zoutb);
5056
}
5157

@@ -54,7 +60,9 @@ nxt_zstd_compress(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf,
5460
ZSTD_freeCStream(zstd);
5561
}
5662

63+
printf("%s: ret [%lu]\n", __func__, ret);
5764
if (ZSTD_isError(ret)) {
65+
printf("%s: [%s]\n", __func__, ZSTD_getErrorName(ret));
5866
return -1;
5967
}
6068

0 commit comments

Comments
 (0)