-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpsim.pl
More file actions
127 lines (99 loc) · 2.5 KB
/
httpsim.pl
File metadata and controls
127 lines (99 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/perl
# Copyright 2018 Rika Lena Denia, comNET GmbH <rika.denia@comnetgmbh.com>
#
# This file is part of HTTPSim.
#
# HTTPSim is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# HTTPSim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with HTTPSim. If not, see <http://www.gnu.org/licenses/>.
#
use strict;
use warnings;
use POE;
use HTTPSim::Server::Dump;
use HTTPSim::Server::Replay;
use Getopt::Long;
use Pod::Usage;
use Log::Log4perl qw/:easy/;
use Log::Log4perl::Level;
BEGIN { Log::Log4perl->easy_init($DEBUG) };
my $mode = 'dump';
my $port = 9090;
my $static_remote = undef;
my $dump_directory = undef;
my $help;
GetOptions(
'mode=s', \$mode,
'port=i', \$port,
'static=s', \$static_remote,
'dump=s', \$dump_directory,
'help', \$help,
);
if ($help) {
pod2usage(
-exitval => 0,
-verbose => 1,
);
}
# Check dump directory
unless (defined($dump_directory)) {
pod2usage(
-message => 'No dump directory specified',
-exitval => 1,
-verbose => 0,
);
}
# Handle mode
$mode =~ tr/A-Z/a-z/;
if ($mode eq 'dump') {
$mode = 'Dump';
}
elsif ($mode eq 'replay') {
$mode = 'Replay';
}
else {
pod2usage(
-message => "Invalid mode specified: \"$mode\"",
-exitval => 1,
-verbose => 0,
);
}
# Prepare
my $server_class = "HTTPSim::Server::$mode";
my %server_args = (
port => $port,
dump_path => $dump_directory,
);
$server_args{static_remote} = $static_remote if $static_remote;
# Construct server
my $server = $server_class->new(%server_args);
POE::Kernel->run_one_timeslice;
# Go
$server->start;
POE::Kernel->run;
=pod
=head1 SYNOPSIS
httpsim --dump DIR [--mode dump|replay] [--port NUMERIC] [--static HOST] [--help]
=head1 ARGUMENTS
=over
=item --dump DIR
Write dumps to or load dumps from directory I<DIR>.
=item --mode dump|replay
Start proxy in dump or replay mode.
Default: dump
=item --port NUMERIC
Start proxy on TCP port I<NUMERIC>.
=item --static HOST
Act as if accessing remote host I<HOST> when receiving a non-proxy request.
=item --help
Show this help
=back