DebugInfo: Styling + add request/response body and fu obj contents
Formatting is still shit.
This commit is contained in:
parent
f52ad9a2e6
commit
af9340f908
2 changed files with 110 additions and 43 deletions
14
FU.pm
14
FU.pm
|
|
@ -3,7 +3,7 @@ use v5.36;
|
|||
use Carp 'confess', 'croak';
|
||||
use IO::Socket;
|
||||
use POSIX ();
|
||||
use Time::HiRes 'clock_gettime', 'CLOCK_MONOTONIC';
|
||||
use Time::HiRes 'time', 'clock_gettime', 'CLOCK_MONOTONIC';
|
||||
use FU::Log 'log_write';
|
||||
use FU::Util;
|
||||
use FU::Validate;
|
||||
|
|
@ -318,7 +318,11 @@ sub _log_err($e) {
|
|||
}
|
||||
|
||||
sub _do_req($c) {
|
||||
local $REQ = { hdr => {}, trace_start => clock_gettime(CLOCK_MONOTONIC), trace_id => sprintf('%010x%08x%04x', int time, $$, int rand 1<<16) };
|
||||
local $REQ = {
|
||||
hdr => {},
|
||||
trace_start => clock_gettime(CLOCK_MONOTONIC),
|
||||
trace_id => sprintf('%012x%06x%04x', int(time*10000) % (1<<(12*4)), $$ % (1<<(6*4)), int rand 1<<16)
|
||||
};
|
||||
local $fu = bless {}, 'FU::obj';
|
||||
|
||||
$REQ->{ip} = $c->{client_sock} isa 'IO::Socket::INET' ? $c->{client_sock}->peerhost : '127.0.0.1';
|
||||
|
|
@ -648,8 +652,8 @@ sub log_verbose($,$msg) {
|
|||
length $r->{body} ? do {
|
||||
my $b = substr $r->{body}, 0, 4096;
|
||||
my $trunc = length $r->{body} > 4096 ? ', truncated' : '';
|
||||
utf8::decode($b) ? ("Body (utf8$trunc)", _fmt_section($b =~ s/\r//rg =~ s/\n{4,}/\n[..]\n/rg))
|
||||
: ("Body (hex$trunc)", _fmt_section(unpack('H*', $b) =~ s/(.{128})/$1\n/rg))
|
||||
utf8::decode($b) ? ("Body (utf8$trunc):", _fmt_section($b =~ s/\r//rg =~ s/\n{4,}/\n[..]\n/rg))
|
||||
: ("Body (hex$trunc):", _fmt_section(unpack('H*', $b) =~ s/(.{128})/$1\n/rg))
|
||||
} : (),
|
||||
'Message:', _fmt_section $msg
|
||||
);
|
||||
|
|
@ -898,10 +902,12 @@ sub _finalize {
|
|||
) {
|
||||
push @vary, 'accept-encoding';
|
||||
if ($hasbrotli && ($r->{hdr}{'accept-encoding'}||'') =~ /\bbr\b/) {
|
||||
$r->{resbody_orig} = $r->{resbody};
|
||||
$r->{resbody} = FU::Util::brotli_compress(6, $r->{resbody});
|
||||
$r->{reshdr}{'content-encoding'} = 'br';
|
||||
|
||||
} elsif ($hasgzip && ($r->{hdr}{'accept-encoding'}||'') =~ /\bgzip\b/) {
|
||||
$r->{resbody_orig} = $r->{resbody};
|
||||
$r->{resbody} = FU::Util::gzip_compress(6, $r->{resbody});
|
||||
$r->{reshdr}{'content-encoding'} = 'gzip';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue