| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Plack::Middleware::RequestId; |
|
2
|
2
|
|
|
2
|
|
72458
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
66
|
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
69
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
561
|
use parent 'Plack::Middleware'; |
|
|
2
|
|
|
|
|
305
|
|
|
|
2
|
|
|
|
|
13
|
|
|
6
|
2
|
|
|
2
|
|
15427
|
use Plack::Util; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
59
|
|
|
7
|
2
|
|
|
|
|
12
|
use Plack::Util::Accessor qw/ |
|
8
|
|
|
|
|
|
|
psgi_env_key |
|
9
|
|
|
|
|
|
|
http_header |
|
10
|
|
|
|
|
|
|
req_http_header |
|
11
|
|
|
|
|
|
|
id_generator |
|
12
|
|
|
|
|
|
|
force_generate_id |
|
13
|
|
|
|
|
|
|
env_key |
|
14
|
|
|
|
|
|
|
no_http_header |
|
15
|
2
|
|
|
2
|
|
12
|
/; |
|
|
2
|
|
|
|
|
5
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $request_id; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub prepare_app { |
|
22
|
8
|
|
|
8
|
1
|
23822
|
my ($self) = @_; |
|
23
|
|
|
|
|
|
|
|
|
24
|
8
|
100
|
|
|
|
38
|
unless ($self->psgi_env_key) { |
|
25
|
7
|
|
|
|
|
107
|
$self->psgi_env_key('psgix.request_id'); |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
8
|
100
|
|
|
|
77
|
unless ($self->http_header) { |
|
29
|
6
|
|
|
|
|
37
|
$self->http_header('X-Request-Id'); |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
8
|
|
|
|
|
56
|
my $req_http_header = 'HTTP_'. uc $self->http_header; |
|
33
|
8
|
|
|
|
|
81
|
$req_http_header =~ s/-/_/g; |
|
34
|
8
|
|
|
|
|
34
|
$self->req_http_header($req_http_header); |
|
35
|
|
|
|
|
|
|
|
|
36
|
8
|
100
|
|
|
|
58
|
unless ($self->id_generator) { |
|
37
|
4
|
|
|
|
|
676
|
require Data::UUID; |
|
38
|
4
|
|
|
|
|
1055
|
Data::UUID->import; |
|
39
|
4
|
|
|
|
|
1140
|
$self->{_uuid_obj} = Data::UUID->new; |
|
40
|
|
|
|
|
|
|
$self->id_generator(sub { |
|
41
|
3
|
|
|
3
|
|
826
|
substr $self->{_uuid_obj}->create_hex, 2, 32; |
|
42
|
4
|
|
|
|
|
47
|
}); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub call { |
|
47
|
8
|
|
|
8
|
1
|
24942
|
my($self, $env) = @_; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$request_id |
|
50
|
|
|
|
|
|
|
= $env->{$self->psgi_env_key} |
|
51
|
|
|
|
|
|
|
= (!$self->force_generate_id && $env->{$self->req_http_header}) |
|
52
|
8
|
100
|
100
|
|
|
36
|
? $env->{$self->req_http_header} |
|
53
|
|
|
|
|
|
|
: $self->id_generator->($env); |
|
54
|
|
|
|
|
|
|
|
|
55
|
8
|
100
|
|
|
|
165
|
if ($self->env_key) { |
|
56
|
1
|
|
|
|
|
7
|
$ENV{$self->env_key} = $request_id; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
8
|
|
|
|
|
96
|
my $res = $self->app->($env); |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$self->response_cb($res, sub { |
|
62
|
8
|
|
|
8
|
|
220
|
my $res = shift; |
|
63
|
8
|
100
|
66
|
|
|
40
|
if ($res && !$self->no_http_header) { |
|
64
|
|
|
|
|
|
|
Plack::Util::header_push( |
|
65
|
|
|
|
|
|
|
$res->[1], |
|
66
|
|
|
|
|
|
|
$self->http_header, |
|
67
|
7
|
|
|
|
|
65
|
$env->{$self->psgi_env_key}, |
|
68
|
|
|
|
|
|
|
); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
8
|
|
|
|
|
832
|
}); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |