diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2023-01-28 18:24:00 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2023-01-28 18:24:00 +0300 |
commit | ba247cbf0b6a5b88f309cfb32585bd8f3eb3abb0 (patch) | |
tree | a4885d08d3c4730258e4e390dca1ab104cc8511c | |
parent | 26e703e68a0324e7e5bfd3442f3e424c88dd2c42 (diff) | |
download | magi-ba247cbf0b6a5b88f309cfb32585bd8f3eb3abb0.tar magi-ba247cbf0b6a5b88f309cfb32585bd8f3eb3abb0.tar.xz magi-ba247cbf0b6a5b88f309cfb32585bd8f3eb3abb0.zip |
Fix content-length
Content-length in response was in reverse order.
-rw-r--r-- | LICENSE | 2 | ||||
-rw-r--r-- | src/response.c | 18 |
2 files changed, 12 insertions, 8 deletions
@@ -1,4 +1,4 @@ -Copyright 2019-2021 Aleksey Veresov +Copyright 2019-2023 Aleksey Veresov This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from diff --git a/src/response.c b/src/response.c index 8809837..ed9d8ae 100644 --- a/src/response.c +++ b/src/response.c @@ -167,15 +167,19 @@ void magi_response_header(struct magi_response *r, void magi_response_content_length(struct magi_response *r, int length) { struct magi_param addon; - int len = 1; - addon.name = magi_str_create_copy("Content-Length", 14); - addon.data = malloc(len + 1); - *addon.data = '0' + length % 10; - while (length /= 10) { - addon.data = realloc(addon.data, len + 2); - addon.data[len] = '0' + length % 10; + int len = 1; + int tmp = length; + addon.name = magi_str_create_copy("Content-Length", 14); + while (tmp /= 10) { ++len; } + addon.data = malloc(len + 1); + addon.data[len - 1] = '0' + length % 10; + length /= 10; + for (tmp = len - 2; tmp >= 0; --tmp) { + addon.data[tmp] = '0' + length % 10; + length /= 10; + } addon.data[len] = 0; magi_params_set(&r->head_entity, &addon); } |