mirror of
https://github.com/ovh/the-bastion.git
synced 2024-12-29 03:31:23 +08:00
enh: httpproxy: add informational headers to the egress side request
This commit is contained in:
parent
15cad00c27
commit
d0e7e9046b
1 changed files with 12 additions and 1 deletions
|
@ -20,6 +20,7 @@ use LWP::UserAgent;
|
|||
use MIME::Base64;
|
||||
use POSIX ();
|
||||
use Storable qw{ freeze thaw };
|
||||
use Sys::Hostname;
|
||||
use Time::HiRes ();
|
||||
|
||||
$ENV{'FORCE_STDERR'} = 1;
|
||||
|
@ -286,6 +287,14 @@ $req->header('Accept-Encoding' => scalar HTTP::Message::decodable());
|
|||
$req->header('Authorization', 'Basic ' . encode_base64($user . ':' . $device_password, ''));
|
||||
undef $device_password; # no longer needed
|
||||
|
||||
$req->header('X-Bastion-Auth-Mode', $authmode);
|
||||
$req->header('X-Bastion-Ingress-Client-IP', $ENV{'REMOTE_ADDR'});
|
||||
$req->header('X-Bastion-Ingress-Client-Port', $ENV{'REMOTE_PORT'});
|
||||
$req->header('X-Bastion-Ingress-Client-User-Agent', $ENV{'HTTP_USER_AGENT'});
|
||||
$req->header('X-Bastion-Ingress-Account', $account);
|
||||
$req->header('X-Bastion-UniqID', $uniqid);
|
||||
$req->header('X-Bastion-Instance', Sys::Hostname::hostname());
|
||||
|
||||
my $start_time = [Time::HiRes::gettimeofday()];
|
||||
|
||||
# to handle timeout properly, we fork a child, he'll do the req, and we'll wait for it,
|
||||
|
@ -385,7 +394,9 @@ my @t = localtime($now[0]);
|
|||
my $headers_as_string = $res ? join("", $res->{'_headers'}->as_string("\n")) : '';
|
||||
my $logfile = sprintf("%s/%s.txt", $finaldir, POSIX::strftime("%F", @t));
|
||||
my $logline = sprintf(
|
||||
"--- BASTION_REQUEST UNIQID=%s TIMESTAMP=%d.%06d DATE=%s ---\n%s\n--- DEVICE_ANSWER UNIQID=%s TIMESTAMP=%d.%06d DATE=%s ---\n%s\n--- END UNIQID=%s TIMESTAMP=%d.%06d DATE=%s ---\n\n",
|
||||
"--- BASTION_REQUEST UNIQID=%s TIMESTAMP=%d.%06d DATE=%s ---\n%s\n".
|
||||
"--- DEVICE_ANSWER UNIQID=%s TIMESTAMP=%d.%06d DATE=%s ---\n%s\n".
|
||||
"--- END UNIQID=%s TIMESTAMP=%d.%06d DATE=%s ---\n\n",
|
||||
$uniqid, $now[0], $now[1], POSIX::strftime("%Y/%m/%d.%H:%M:%S", @t), $req->as_string(),
|
||||
$uniqid, $now[0], $now[1], POSIX::strftime("%Y/%m/%d.%H:%M:%S", @t),
|
||||
($res ? sprintf("%s %s\n%s\n%s", $res->protocol, $res->status_line, $headers_as_string, $res->decoded_content) : '(DEVICE TIMEOUT)'),
|
||||
|
|
Loading…
Reference in a new issue