diff options
| author | Andrew Clayton <a.clayton@nginx.com> | 2024-11-29 15:46:11 +0000 |
|---|---|---|
| committer | Andrew Clayton <a.clayton@nginx.com> | 2025-04-14 18:11:53 +0100 |
| commit | adaecb6f9efcf435e09c57ecb095f8109d17a817 (patch) | |
| tree | 3d1b4694da8c9c831ad1f414349fbfb6ac4a5603 /src/nxt_http_static.c | |
| parent | 523d42269ff89490b9dad25565121ea5e7696881 (diff) | |
| download | unit-adaecb6f9efcf435e09c57ecb095f8109d17a817.tar.gz unit-adaecb6f9efcf435e09c57ecb095f8109d17a817.tar.bz2 | |
http: Compress static responses
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
Diffstat (limited to '')
| -rw-r--r-- | src/nxt_http_static.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index d56ec587..78b1f150 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -5,6 +5,7 @@ #include <nxt_router.h> #include <nxt_http.h> +#include <nxt_http_compression.h> typedef struct { @@ -576,7 +577,37 @@ nxt_http_static_send(nxt_task_t *task, nxt_http_request_t *r, field->value_length = mtype->length; } + r->resp.mime_type = mtype; + if (ctx->need_body && nxt_file_size(&fi) > 0) { + ret = nxt_http_comp_check_compression(task, r); + if (ret == NXT_HTTP_NOT_ACCEPTABLE) { + nxt_http_request_error(task, r, NXT_HTTP_NOT_ACCEPTABLE); + return; + } else if (ret != NXT_OK) { + goto fail; + } + + if (nxt_http_comp_wants_compression()) { + size_t out_total; + nxt_int_t ret; + + ret = nxt_http_comp_compress_static_response( + task, &f, &fi, + NXT_HTTP_STATIC_BUF_SIZE, + &out_total); + if (ret == NXT_ERROR) { + goto fail; + } + + ret = nxt_file_info(f, &fi); + if (nxt_slow_path(ret != NXT_OK)) { + goto fail; + } + + r->resp.content_length_n = out_total; + } + fb = nxt_mp_zget(r->mem_pool, NXT_BUF_FILE_SIZE); if (nxt_slow_path(fb == NULL)) { goto fail; |
