diff --git a/src/nxt_brotli.c b/src/nxt_brotli.c index 01ef060ff..c0863eff0 100644 --- a/src/nxt_brotli.c +++ b/src/nxt_brotli.c @@ -2,6 +2,10 @@ * */ +#define _GNU_SOURCE +#include + + #include #include #include @@ -27,6 +31,9 @@ nxt_brotli_init(nxt_http_comp_compressor_ctx_t *ctx) *brotli = BrotliEncoderCreateInstance(NULL, NULL, NULL); BrotliEncoderSetParameter(*brotli, BROTLI_PARAM_QUALITY, ctx->level); + + printf("%7d %s: brotli compression level [%d]\n", gettid(), __func__, + ctx->level); } @@ -45,6 +52,10 @@ nxt_brotli_compress(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf, size_t out_bytes = out_len; BrotliEncoderState *brotli = ctx->brotli_ctx; + printf("%7d %s: last/%s\n", gettid(), __func__, last ? "true" : "false"); + printf("%7d %s: in_len [%lu] out_len [%lu]\n", gettid(), __func__, + in_len, out_len); + ok = BrotliEncoderCompressStream(brotli, BROTLI_OPERATION_PROCESS, &in_len, &in_buf, &out_bytes, &out_buf, NULL); @@ -53,6 +64,8 @@ nxt_brotli_compress(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf, &in_len, &in_buf, &out_bytes, &out_buf, NULL); + printf("%7d %s: in_len [%lu] out_len [%lu] out_bytes [%lu]\n", gettid(), + __func__, in_len, out_len, out_bytes); if (last) { ok = BrotliEncoderCompressStream(brotli, BROTLI_OPERATION_FINISH, &in_len, &in_buf, &out_bytes, @@ -60,6 +73,9 @@ nxt_brotli_compress(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf, nxt_brotli_free(ctx); } + printf("%7d %s: in_len [%lu] out_len [%lu] out_bytes [%lu]\n", gettid(), + __func__, in_len, out_len, out_bytes); + return out_len - out_bytes; } diff --git a/src/nxt_http_compression.c b/src/nxt_http_compression.c index b9a5534a0..bb5df851c 100644 --- a/src/nxt_http_compression.c +++ b/src/nxt_http_compression.c @@ -133,6 +133,25 @@ static const nxt_http_comp_type_t compressors[] = { }; +static void print_compressor(const nxt_http_comp_compressor_t *c) +{ + printf("token : %s\n", c->type->token.start); + printf("scheme : %d\n", c->type->scheme); + printf("level : %d\n", c->opts.level); + printf("min_len : %ld\n", c->opts.min_len); +} + +static void print_comp_config(size_t n) +{ + for (size_t i = 0; i < n; i++) { + nxt_http_comp_compressor_t *compr = enabled_compressors + i; + + print_compressor(compr); + printf("\n"); + } +} + + static ssize_t nxt_http_comp_compress(uint8_t *dst, size_t dst_size, const uint8_t *src, 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) // nxt_buf_t *buf; nxt_http_comp_ctx_t *ctx = &compressor_ctx; + printf("%s: \n", __func__); + if (ctx->idx == NXT_HTTP_COMP_SCHEME_IDENTITY) { + printf("%s: NXT_HTTP_COMP_SCHEME_IDENTITY [skipping/identity]\n", + __func__); return NXT_OK; } @@ -185,14 +208,19 @@ nxt_http_comp_compress_app_response(nxt_http_request_t *r, nxt_buf_t **b) in_len = (*b)->mem.free - (*b)->mem.pos; buf_len = nxt_http_comp_bound(in_len); + printf("%s: in_len [%lu] buf_len [%lu] last [%s]\n", __func__, + in_len, buf_len, last ? "true" : "false"); + #if 1 if (buf_len > (size_t)nxt_buf_mem_size(&(*b)->mem)) { + /* XXX Un-skip Content-Length header, or not... */ return NXT_OK; } uint8_t *buf = nxt_malloc(buf_len); cbytes = nxt_http_comp_compress(buf, buf_len, (*b)->mem.pos, in_len, last); + printf("%s: cbytes = %ld\n", __func__, cbytes); if (cbytes == -1) { nxt_free(buf); return NXT_ERROR; @@ -307,8 +335,12 @@ nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f, last = n == rest; + printf("%s: out_off [%ld] in_off [%ld] last [%s]\n", + __func__, *out_total, in_size - rest, last ? "true" : "false"); + cbytes = nxt_http_comp_compress(out + *out_total, out_size - *out_total, in + in_size - rest, n, last); + printf("%s: cbytes [%ld]\n", __func__, cbytes); *out_total += cbytes; rest -= n; @@ -337,6 +369,8 @@ nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f, bool nxt_http_comp_wants_compression(void) { + printf("%s: compression [%s]\n", __func__, + compressor_ctx.idx > 0 ? "true" : "false"); return compressor_ctx.idx; } @@ -411,6 +445,9 @@ nxt_http_comp_select_compressor(const nxt_str_t *token) scheme = enabled_compressors[ecidx].type->scheme; + printf("%s: %.*s [%f] [%d:%d]\n", __func__, (int)enc.length, enc.start, + qval, ecidx, scheme); + if (qval == 0.0 && scheme == NXT_HTTP_COMP_SCHEME_IDENTITY) { identity_allowed = false; } @@ -425,6 +462,12 @@ nxt_http_comp_select_compressor(const nxt_str_t *token) free(str); + printf("%s: Selected compressor : %s\n", __func__, + enabled_compressors[idx].type->token.start); + + printf("%s: idx [%u], identity_allowed [%s]\n", __func__, idx, + identity_allowed ? "true" : "false"); + if (idx == NXT_HTTP_COMP_SCHEME_IDENTITY && !identity_allowed) { return -1; } @@ -442,6 +485,14 @@ nxt_http_comp_set_header(nxt_http_request_t *r, nxt_uint_t comp_idx) static const nxt_str_t content_encoding_str = nxt_string("Content-Encoding"); + printf("%s: \n", __func__); + +#if 0 + if (comp_idx == NXT_HTTP_COMP_SCHEME_IDENTITY) { + return NXT_OK; + } +#endif + f = nxt_list_add(r->resp.fields); if (nxt_slow_path(f == NULL)) { return NXT_ERROR; @@ -470,6 +521,8 @@ nxt_http_comp_set_header(nxt_http_request_t *r, nxt_uint_t comp_idx) if (nxt_strcasecmp(f->name, (const u_char *)"Content-Length") == 0) { + printf("%s: Found (%s: %s), marking as 'skip'\n", __func__, + f->name, f->value); f->skip = true; break; } @@ -485,7 +538,10 @@ nxt_http_comp_is_resp_content_encoded(const nxt_http_request_t *r) { nxt_http_field_t *f; + printf("%s: \n", __func__); + nxt_list_each(f, r->resp.fields) { + printf("%s: %s: %s\n", __func__, f->name, f->value); if (nxt_strcasecmp(f->name, (const u_char *)"Content-Encoding") == 0) { return true; } @@ -504,6 +560,8 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r) nxt_router_conf_t *rtcf; nxt_http_comp_compressor_t *compressor; + printf("%s: \n", __func__); + compressor_ctx = (nxt_http_comp_ctx_t){ .resp_clen = -1 }; if (nr_enabled_compressors == 0) { @@ -525,10 +583,15 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r) return NXT_OK; } + printf("%s: Response Content-Type [%.*s]\n", __func__, + (int)mime_type.length, mime_type.start); + if (mime_types_rule != NULL) { ret = nxt_http_route_test_rule(r, mime_types_rule, mime_type.start, mime_type.length); + printf("%s: mime_type : %d (%.*s)\n", __func__, ret, + (int)mime_type.length, mime_type.start); if (ret == 0) { return NXT_OK; } @@ -577,7 +640,11 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r) min_len = compressor->opts.min_len; + printf("%s: content_length [%ld] min_len [%ld]\n", __func__, + compressor_ctx.resp_clen, min_len); if (compressor_ctx.resp_clen > -1 && compressor_ctx.resp_clen < min_len) { + printf("%s: %ld < %ld [skipping/clen]\n", __func__, + compressor_ctx.resp_clen , min_len); return NXT_OK; } @@ -631,6 +698,8 @@ nxt_http_comp_set_compressor(nxt_task_t *task, nxt_router_conf_t *rtcf, static const nxt_str_t token_str = nxt_string("encoding"); + printf("%s: \n", __func__); + obj = nxt_conf_get_object_member(comp, &token_str, NULL); if (obj == NULL) { return NXT_ERROR; @@ -644,6 +713,7 @@ nxt_http_comp_set_compressor(nxt_task_t *task, nxt_router_conf_t *rtcf, compr->type = &compressors[cidx]; compr->opts.level = compr->type->def_compr; compr->opts.min_len = -1; + printf("%s: %s\n", __func__, compr->type->token.start); ret = nxt_conf_map_object(rtcf->mem_pool, comp, compressors_opts_map, nxt_nitems(compressors_opts_map), &compr->opts); @@ -678,6 +748,8 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf, static const nxt_str_t comps_str = nxt_string("compressors"); static const nxt_str_t mimes_str = nxt_string("types"); + printf("%s: \n", __func__); + mimes = nxt_conf_get_object_member(comp_conf, &mimes_str, NULL); if (mimes != NULL) { mime_types_rule = nxt_http_route_types_rule_create(task, @@ -715,6 +787,7 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf, .opts.min_len = -1 }; if (nxt_conf_type(comps) == NXT_CONF_OBJECT) { + print_comp_config(nr_enabled_compressors); return nxt_http_comp_set_compressor(task, rtcf, comps, 1); } @@ -728,5 +801,7 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf, } } + print_comp_config(nr_enabled_compressors); + return NXT_OK; } diff --git a/src/nxt_http_request.c b/src/nxt_http_request.c index 722197b8a..1ecefcd45 100644 --- a/src/nxt_http_request.c +++ b/src/nxt_http_request.c @@ -320,6 +320,8 @@ nxt_http_request_start(nxt_task_t *task, void *obj, void *data) nxt_socket_conf_t *skcf; nxt_http_request_t *r; + printf("%s: \n", __func__); + r = obj; NXT_OTEL_TRACE(); @@ -692,6 +694,8 @@ nxt_http_request_header_send(nxt_task_t *task, nxt_http_request_t *r, nxt_http_field_t *server, *date, *content_length; nxt_socket_conf_t *skcf; + printf("%s: \n", __func__); + ret = nxt_http_set_headers(r); if (nxt_slow_path(ret != NXT_OK)) { goto fail; @@ -783,6 +787,9 @@ void nxt_http_request_send(nxt_task_t *task, nxt_http_request_t *r, nxt_buf_t *out) { if (nxt_fast_path(r->proto.any != NULL)) { + printf("%s: sending [%lu] bytes\n", __func__, + nxt_buf_mem_used_size(&out->mem)); + nxt_http_proto[r->protocol].send(task, r, out); } } diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c index bd0646f3b..e08fc9866 100644 --- a/src/nxt_http_route.c +++ b/src/nxt_http_route.c @@ -688,6 +688,8 @@ nxt_http_action_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, nxt_router_conf_t *rtcf; nxt_http_action_conf_t acf; + printf("%s: \n", __func__); + nxt_memzero(&acf, sizeof(acf)); ret = nxt_conf_map_object(tmcf->mem_pool, cv, nxt_http_route_action_conf, diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 6db74c357..d52eeacf8 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -327,6 +327,8 @@ nxt_http_static_send(nxt_task_t *task, nxt_http_request_t *r, nxt_work_handler_t body_handler; nxt_http_static_conf_t *conf; + printf("%s: \n", __func__); + action = ctx->action; conf = action->u.conf; rtcf = r->conf->socket_conf->router_conf; @@ -821,6 +823,8 @@ nxt_http_static_body_handler(nxt_task_t *task, void *obj, void *data) nxt_work_queue_t *wq; nxt_http_request_t *r; + printf("%s: \n", __func__); + r = obj; fb = r->out; @@ -881,6 +885,8 @@ nxt_http_static_buf_completion(nxt_task_t *task, void *obj, void *data) nxt_off_t rest; nxt_http_request_t *r; + printf("%s: \n", __func__); + b = obj; r = data; diff --git a/src/nxt_router.c b/src/nxt_router.c index ff2dbb545..28c0888f9 100644 --- a/src/nxt_router.c +++ b/src/nxt_router.c @@ -4136,6 +4136,8 @@ nxt_router_response_ready_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg, nxt_unit_response_t *resp; nxt_request_rpc_data_t *req_rpc_data; + printf("%s: \n", __func__); + req_rpc_data = data; r = req_rpc_data->request; diff --git a/src/nxt_zlib.c b/src/nxt_zlib.c index d5cf03c3a..3530040f0 100644 --- a/src/nxt_zlib.c +++ b/src/nxt_zlib.c @@ -59,11 +59,14 @@ nxt_zlib_deflate(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf, z->avail_out = out_len; z->next_out = out_buf; + printf("%s: in_len [%lu], out_len [%lu]\n", __func__, in_len, out_len); + compressed_bytes = z->total_out; ret = deflate(z, last ? Z_FINISH : Z_SYNC_FLUSH); if (ret == Z_STREAM_ERROR || ret == Z_BUF_ERROR) { deflateEnd(z); + printf("%s: ret = %d\n", __func__, ret); return -1; } diff --git a/src/nxt_zstd.c b/src/nxt_zstd.c index 96268ba86..3877ca8c6 100644 --- a/src/nxt_zstd.c +++ b/src/nxt_zstd.c @@ -27,6 +27,8 @@ nxt_zstd_init(nxt_http_comp_compressor_ctx_t *ctx) *zstd = ZSTD_createCStream(); ZSTD_initCStream(*zstd, ctx->level); + + printf("%s: zstd compression level [%d]\n", __func__, ctx->level); } @@ -46,9 +48,13 @@ nxt_zstd_compress(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf, ZSTD_inBuffer zinb = { .src = in_buf, .size = in_len }; ZSTD_outBuffer zoutb = { .dst = out_buf, .size = out_len }; + printf("%s: in_len [%lu] out_len [%lu] last [%s]\n", __func__, + in_len, out_len, last ? "true" : "false"); + ret = ZSTD_compressStream(zstd, &zoutb, &zinb); if (zinb.pos < zinb.size) { + printf("%s: short by [%d]\n", __func__, zinb.pos < zinb.size); ret = ZSTD_flushStream(zstd, &zoutb); } @@ -57,7 +63,9 @@ nxt_zstd_compress(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf, nxt_zstd_free(ctx); } + printf("%s: ret [%lu]\n", __func__, ret); if (ZSTD_isError(ret)) { + printf("%s: [%s]\n", __func__, ZSTD_getErrorName(ret)); return -1; }