summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_js.c
diff options
context:
space:
mode:
authorZhidao HONG <z.hong@f5.com>2024-10-14 15:10:06 +0800
committerZhidao HONG <z.hong@f5.com>2024-10-22 13:40:50 +0800
commitde430edae585d40dacec20dcf4324d7c0ee8fba1 (patch)
treef8f87e2a5c456b9608c81cadf61dd04cf72e2e6e /src/nxt_js.c
parentf6036bbc7c798133e95d107ef99f289281366b0d (diff)
downloadunit-de430edae585d40dacec20dcf4324d7c0ee8fba1.tar.gz
unit-de430edae585d40dacec20dcf4324d7c0ee8fba1.tar.bz2
Add flag for newline control in access log entries
This commit introduces a new flag to control the addition of newline characters in access log entries. This is prepared for fixing the issue where log entries lack newlines when using JS configuration.
Diffstat (limited to 'src/nxt_js.c')
-rw-r--r--src/nxt_js.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/nxt_js.c b/src/nxt_js.c
index d46231bd..0482482a 100644
--- a/src/nxt_js.c
+++ b/src/nxt_js.c
@@ -230,7 +230,7 @@ nxt_js_add_module(nxt_js_conf_t *jcf, nxt_str_t *name, nxt_str_t *text)
nxt_js_t *
-nxt_js_add_tpl(nxt_js_conf_t *jcf, nxt_str_t *str, nxt_bool_t strz)
+nxt_js_add_tpl(nxt_js_conf_t *jcf, nxt_str_t *str, nxt_uint_t flags)
{
size_t size;
u_char *p, *start;
@@ -243,13 +243,19 @@ nxt_js_add_tpl(nxt_js_conf_t *jcf, nxt_str_t *str, nxt_bool_t strz)
" return ");
/*
- * Appending a terminating null character if strz is true.
+ * Append a newline character if newline is true.
+ * Append a terminating null character if strz is true.
*/
+ static const nxt_str_t newline_str = nxt_string(" + '\\x0A'");
static const nxt_str_t strz_str = nxt_string(" + '\\x00'");
size = func_str.length + str->length + 1;
- if (strz) {
+ if (flags & NXT_TSTR_NEWLINE) {
+ size += newline_str.length;
+ }
+
+ if (flags & NXT_TSTR_STRZ) {
size += strz_str.length;
}
@@ -263,7 +269,11 @@ nxt_js_add_tpl(nxt_js_conf_t *jcf, nxt_str_t *str, nxt_bool_t strz)
p = nxt_cpymem(p, func_str.start, func_str.length);
p = nxt_cpymem(p, str->start, str->length);
- if (strz) {
+ if (flags & NXT_TSTR_NEWLINE) {
+ p = nxt_cpymem(p, newline_str.start, newline_str.length);
+ }
+
+ if (flags & NXT_TSTR_STRZ) {
p = nxt_cpymem(p, strz_str.start, strz_str.length);
}