@@ -66,38 +66,38 @@ my $ua = Mojo::UserAgent->new(
66
66
# Normal non-blocking request
67
67
my $result ;
68
68
$ua -> get(
69
- " https://127.0.0.1 :$port /" => sub {
69
+ " https://localhost :$port /" => sub {
70
70
my ($ua , $tx ) = @_ ;
71
71
$result = $tx -> res-> body;
72
72
Mojo::IOLoop-> stop;
73
73
}
74
74
);
75
75
Mojo::IOLoop-> start;
76
- is $result , " Hello World! / https://127.0.0.1 :$port /" , ' right content' ;
76
+ is $result , " Hello World! / https://localhost :$port /" , ' right content' ;
77
77
78
78
# Broken redirect
79
79
my $start ;
80
80
$ua -> on(start => sub { $start ++; pop -> req-> headers-> header(' X-Works' , ' it does!' ) });
81
81
$result = undef ;
82
82
my $works ;
83
83
$ua -> max_redirects(3)-> get(
84
- " https://127.0.0.1 :$port /broken_redirect" => sub {
84
+ " https://localhost :$port /broken_redirect" => sub {
85
85
my ($ua , $tx ) = @_ ;
86
86
$result = $tx -> res-> body;
87
87
$works = $tx -> res-> headers-> header(' X-Works' );
88
88
Mojo::IOLoop-> stop;
89
89
}
90
90
);
91
91
Mojo::IOLoop-> start;
92
- is $result , " Hello World! / https://127.0.0.1 :$port /" , ' right content' ;
92
+ is $result , " Hello World! / https://localhost :$port /" , ' right content' ;
93
93
is $works , ' it does!' , ' right header' ;
94
94
is $start , 2, ' redirected once' ;
95
95
$ua -> unsubscribe(' start' );
96
96
97
97
# Normal WebSocket
98
98
$result = undef ;
99
99
$ua -> websocket(
100
- " wss://127.0.0.1 :$port /test" => sub {
100
+ " wss://localhost :$port /test" => sub {
101
101
my ($ua , $tx ) = @_ ;
102
102
$tx -> on(finish => sub { Mojo::IOLoop-> stop });
103
103
$tx -> on(message => sub { shift -> finish; $result = shift });
@@ -112,7 +112,7 @@ $ua->proxy->https("http://sri:secr3t\@127.0.0.1:$proxy");
112
112
$result = undef ;
113
113
my ($auth , $kept_alive );
114
114
$ua -> get(
115
- " https://127.0.0.1 :$port /proxy" => sub {
115
+ " https://localhost :$port /proxy" => sub {
116
116
my ($ua , $tx ) = @_ ;
117
117
$result = $tx -> res-> body;
118
118
$auth = $tx -> req-> headers-> proxy_authorization;
@@ -123,27 +123,27 @@ $ua->get(
123
123
Mojo::IOLoop-> start;
124
124
ok !$auth , ' no "Proxy-Authorization" header' ;
125
125
ok !$kept_alive , ' connection was not kept alive' ;
126
- is $result , " https://127.0.0.1 :$port /proxy" , ' right content' ;
126
+ is $result , " https://localhost :$port /proxy" , ' right content' ;
127
127
128
128
# Non-blocking kept alive proxy request
129
129
($kept_alive , $result ) = ();
130
130
$ua -> get(
131
- " https://127.0.0.1 :$port /proxy" => sub {
131
+ " https://localhost :$port /proxy" => sub {
132
132
my ($ua , $tx ) = @_ ;
133
133
$kept_alive = $tx -> kept_alive;
134
134
$result = $tx -> res-> body;
135
135
Mojo::IOLoop-> stop;
136
136
}
137
137
);
138
138
Mojo::IOLoop-> start;
139
- is $result , " https://127.0.0.1 :$port /proxy" , ' right content' ;
139
+ is $result , " https://localhost :$port /proxy" , ' right content' ;
140
140
ok $kept_alive , ' connection was kept alive' ;
141
141
142
142
# Kept alive proxy WebSocket
143
143
$ua -> proxy-> https(" http://127.0.0.1:$proxy " );
144
144
($kept_alive , $result ) = ();
145
145
$ua -> websocket(
146
- " wss://127.0.0.1 :$port /test" => sub {
146
+ " wss://localhost :$port /test" => sub {
147
147
my ($ua , $tx ) = @_ ;
148
148
$kept_alive = $tx -> kept_alive;
149
149
$tx -> on(finish => sub { Mojo::IOLoop-> stop });
@@ -157,23 +157,23 @@ is $result, 'test1test2', 'right result';
157
157
158
158
# Blocking proxy requests
159
159
$ua -> proxy-> https(" http://sri:secr3t\@ 127.0.0.1:$proxy " );
160
- my $tx = $ua -> max_connections(0)-> get(" https://127.0.0.1 :$port /proxy" );
160
+ my $tx = $ua -> max_connections(0)-> get(" https://localhost :$port /proxy" );
161
161
is $tx -> res-> code, 200, ' right status' ;
162
- is $tx -> res-> body, " https://127.0.0.1 :$port /proxy" , ' right content' ;
162
+ is $tx -> res-> body, " https://localhost :$port /proxy" , ' right content' ;
163
163
is $tx -> req-> method, ' GET' , ' right method' ;
164
164
is $tx -> previous-> req-> method, ' CONNECT' , ' right method' ;
165
- $tx = $ua -> max_connections(5)-> get(" https://127.0.0.1 :$port /proxy" );
165
+ $tx = $ua -> max_connections(5)-> get(" https://localhost :$port /proxy" );
166
166
ok !$tx -> kept_alive, ' connection was not kept alive' ;
167
167
is $tx -> res-> code, 200, ' right status' ;
168
- is $tx -> res-> body, " https://127.0.0.1 :$port /proxy" , ' right content' ;
168
+ is $tx -> res-> body, " https://localhost :$port /proxy" , ' right content' ;
169
169
is $tx -> req-> method, ' GET' , ' right method' ;
170
170
is $tx -> previous-> req-> method, ' CONNECT' , ' right method' ;
171
171
172
172
# Proxy WebSocket with bad target
173
173
$ua -> proxy-> https(" http://127.0.0.1:$proxy " );
174
174
my ($leak , $err );
175
175
$ua -> websocket(
176
- " wss://127.0.0.1 :0/test" => sub {
176
+ " wss://localhost :0/test" => sub {
177
177
my ($ua , $tx ) = @_ ;
178
178
$leak = !!Mojo::IOLoop-> stream($tx -> previous-> connection);
179
179
$err = $tx -> error;
@@ -185,9 +185,9 @@ ok !$leak, 'connection has been removed';
185
185
is $err -> {message }, ' Proxy connection failed' , ' right error' ;
186
186
187
187
# Blocking proxy request again
188
- $tx = $ua -> get(" https://127.0.0.1 :$port /proxy" );
188
+ $tx = $ua -> get(" https://localhost :$port /proxy" );
189
189
is $tx -> res-> code, 200, ' right status' ;
190
- is $tx -> res-> body, " https://127.0.0.1 :$port /proxy" , ' right content' ;
190
+ is $tx -> res-> body, " https://localhost :$port /proxy" , ' right content' ;
191
191
192
192
# Failed TLS handshake through proxy
193
193
my $close = Mojo::IOLoop-> acceptor(Mojo::IOLoop-> server(sub {
@@ -214,13 +214,13 @@ $ua->connect_timeout(10);
214
214
$ua = Mojo::UserAgent-> new;
215
215
$proxy = Mojo::IOLoop::Server-> generate_port;
216
216
$ua -> proxy-> https(" http://127.0.0.1:$proxy " );
217
- $tx = $ua -> get(" https://127.0.0.1 :$port /proxy" );
217
+ $tx = $ua -> get(" https://localhost :$port /proxy" );
218
218
is $tx -> error-> {message }, ' Proxy connection failed' , ' right error' ;
219
219
220
220
# Non-blocking request to bad proxy
221
221
$err = undef ;
222
222
$ua -> get(
223
- " https://127.0.0.1 :$port /proxy" => sub {
223
+ " https://localhost :$port /proxy" => sub {
224
224
my ($ua , $tx ) = @_ ;
225
225
$err = $tx -> error;
226
226
Mojo::IOLoop-> stop;
0 commit comments