summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2021-08-25 18:41:52 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2021-09-08 15:06:07 -0400
commit7a21b3856e30d307934a286c2b70aa9455820e68 (patch)
tree5b3a2ae5217572f2728f97b9e46d87abb7322f2f
parent41d4ffad99ac6675357893cafdca4ae0d98dafa6 (diff)
downloadlighttpd-git-7a21b3856e30d307934a286c2b70aa9455820e68.tar.gz
[core] log_error_multiline()
rename log_error_multiline_buffer() to log_error_multiline() and take (char *)ptr and (size_t)len instead of (buffer *)b When debug printing request and response headers, print each header on separate line for readability and omit '\r' if "\r\n" ends line
-rw-r--r--src/connections.c5
-rw-r--r--src/log.c29
-rw-r--r--src/log.h4
-rw-r--r--src/mod_fastcgi.c4
-rw-r--r--src/request.c4
-rw-r--r--src/response.c3
6 files changed, 26 insertions, 23 deletions
diff --git a/src/connections.c b/src/connections.c
index 8044b831..58021d3c 100644
--- a/src/connections.c
+++ b/src/connections.c
@@ -772,9 +772,8 @@ static int connection_handle_read_state(connection * const con) {
r->rqst_header_len = header_len;
if (r->conf.log_request_header)
- log_error(r->conf.errh, __FILE__, __LINE__,
- "fd: %d request-len: %d\n%.*s", con->fd,
- (int)header_len, (int)header_len, hdrs);
+ log_error_multiline(r->conf.errh, __FILE__, __LINE__,
+ hdrs, header_len, "fd:%d rqst: ", con->fd);
http_request_headers_process(r, hdrs, hoff, con->proto_default_port);
chunkqueue_mark_written(cq, r->rqst_header_len);
connection_set_state(r, CON_STATE_REQUEST_END);
diff --git a/src/log.c b/src/log.c
index 39cf2aa2..ef3db440 100644
--- a/src/log.c
+++ b/src/log.c
@@ -247,13 +247,14 @@ log_perror (log_error_st * const errh,
void
-log_error_multiline_buffer (log_error_st * const restrict errh,
- const char * const restrict filename,
- const unsigned int line,
- const buffer * const restrict multiline,
- const char * const restrict fmt, ...)
+log_error_multiline (log_error_st * const restrict errh,
+ const char * const restrict filename,
+ const unsigned int line,
+ const char * const restrict multiline,
+ const size_t len,
+ const char * const restrict fmt, ...)
{
- if (multiline->used < 2) return;
+ if (0 == len) return;
const int errnum = errno;
buffer * const b = &errh->b;
@@ -264,17 +265,19 @@ log_error_multiline_buffer (log_error_st * const restrict errh,
log_buffer_vprintf(b, fmt, ap);
va_end(ap);
- const size_t prefix_len = buffer_clen(b);
- const char * const end = multiline->ptr + multiline->used - 2;
- const char *pos = multiline->ptr-1, *current_line;
- do {
- pos = strchr(current_line = pos+1, '\n');
+ const uint32_t prefix_len = buffer_clen(b);
+ const char * const end = multiline + len;
+ for (const char *pos = multiline; pos < end; ++pos) {
+ const char * const current_line = pos;
+ pos = strchr(pos, '\n');
if (!pos)
pos = end;
+ size_t n = (size_t)(pos - current_line);
+ if (n && current_line[n-1] == '\r') --n; /*(skip "\r\n")*/
buffer_truncate(b, prefix_len);
- log_buffer_append_encoded(b, current_line, pos - current_line);
+ log_buffer_append_encoded(b, current_line, n);
log_write(errh, b);
- } while (pos < end);
+ }
errno = errnum;
}
diff --git a/src/log.h b/src/log.h
index a1e0d466..ec1ad51f 100644
--- a/src/log.h
+++ b/src/log.h
@@ -42,7 +42,7 @@ __attribute_format__((__printf__, 4, 5))
void log_perror(log_error_st *errh, const char *filename, unsigned int line, const char *fmt, ...);
__attribute_cold__
-__attribute_format__((__printf__, 5, 6))
-void log_error_multiline_buffer(log_error_st *errh, const char *filename, unsigned int line, const buffer *multiline, const char *fmt, ...);
+__attribute_format__((__printf__, 6, 7))
+void log_error_multiline(log_error_st *errh, const char *filename, unsigned int line, const char * restrict multiline, const size_t len, const char *fmt, ...);
#endif
diff --git a/src/mod_fastcgi.c b/src/mod_fastcgi.c
index 189b02c8..aae72a6d 100644
--- a/src/mod_fastcgi.c
+++ b/src/mod_fastcgi.c
@@ -462,8 +462,8 @@ static handler_t fcgi_recv_parse(request_st * const r, struct http_response_opts
buffer * const tb = r->tmp_buf;
buffer_clear(tb);
fastcgi_get_packet_body(tb, hctx, &packet);
- log_error_multiline_buffer(r->conf.errh, __FILE__, __LINE__, tb,
- "FastCGI-stderr:");
+ log_error_multiline(r->conf.errh, __FILE__, __LINE__,
+ BUF_PTR_LEN(tb), "FastCGI-stderr:");
}
break;
case FCGI_END_REQUEST:
diff --git a/src/request.c b/src/request.c
index 95a82221..8366986c 100644
--- a/src/request.c
+++ b/src/request.c
@@ -1266,8 +1266,8 @@ http_request_headers_process (request_st * const restrict r, char * const restri
if (r->conf.log_request_header_on_error) {
/*(http_request_parse_headers() modifies hdrs only to
* undo line-wrapping in-place using spaces)*/
- log_error(r->conf.errh, __FILE__, __LINE__,
- "request-header:\n%.*s", (int)r->rqst_header_len, hdrs);
+ log_error_multiline(r->conf.errh, __FILE__, __LINE__,
+ hdrs, r->rqst_header_len, "rqst: ");
}
}
}
diff --git a/src/response.c b/src/response.c
index 1f0a69cd..bb2bbb04 100644
--- a/src/response.c
+++ b/src/response.c
@@ -161,7 +161,8 @@ http_response_write_header (request_st * const r)
r->resp_header_len = buffer_clen(b);
if (r->conf.log_response_header) {
- log_error(r->conf.errh,__FILE__,__LINE__,"Response-Header:\n%s",b->ptr);
+ log_error_multiline(r->conf.errh, __FILE__, __LINE__,
+ BUF_PTR_LEN(b), "fd:%d resp: ", r->con->fd);
}
chunkqueue_prepend_buffer_commit(cq);