[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
personal/stbuehler/tests-path
Glenn Strauss 2021-08-25 18:41:52 -04:00
parent 41d4ffad99
commit 7a21b3856e
6 changed files with 26 additions and 23 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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:

View File

@ -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: ");
}
}
}

View File

@ -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);