@@ -99,67 +99,80 @@ Mojo::IOLoop->singleton->reactor->io(
99
99
}
100
100
);
101
101
102
- # Failed authentication with SOCKS proxy
103
- my $ua = Mojo::UserAgent-> new(ioloop => Mojo::IOLoop-> singleton, insecure => 1);
104
- $ua -> proxy-> http(" socks://foo:baz\@ 127.0.0.1:$port " );
105
- my $tx = $ua -> get(' /' );
106
- ok $tx -> error, ' has error' ;
107
-
108
- # Simple request with SOCKS proxy
109
- $ua -> proxy-> http(" socks://foo:bar\@ 127.0.0.1:$port " );
110
- $tx = $ua -> get(' /' );
111
- ok !$tx -> error, ' no error' ;
112
- ok !$tx -> kept_alive, ' kept connection not alive' ;
113
- ok $tx -> keep_alive, ' keep connection alive' ;
114
- is $tx -> res-> code, 200, ' right status' ;
115
- is $tx -> req-> headers-> proxy_authorization, undef , ' no "Proxy-Authorization" value' ;
116
- is $tx -> res-> body, $last , ' right content' ;
117
- isnt(Mojo::IOLoop-> stream($tx -> connection)-> handle-> sockport, $last , ' different ports' );
118
-
119
- # Keep alive request with SOCKS proxy
120
- my $before = $last ;
121
- $tx = $ua -> get(' /' );
122
- ok !$tx -> error, ' no error' ;
123
- ok $tx -> kept_alive, ' kept connection alive' ;
124
- ok $tx -> keep_alive, ' keep connection alive' ;
125
- is $tx -> res-> code, 200, ' right status' ;
126
- is $tx -> res-> body, $last , ' right content' ;
127
- is $before , $last , ' same port' ;
128
- isnt(Mojo::IOLoop-> stream($tx -> connection)-> handle-> sockport, $last , ' different ports' );
129
-
130
- # WebSocket with SOCKS proxy
131
- my ($result , $id );
132
- $ua -> websocket(
133
- ' /echo' => sub {
134
- my ($ua , $tx ) = @_ ;
135
- $id = $tx -> connection;
136
- $tx -> on(message => sub { $result = pop ; Mojo::IOLoop-> stop });
137
- $tx -> send (' test' );
138
- }
139
- );
140
- Mojo::IOLoop-> start;
141
- is $result , $last , ' right result' ;
142
- isnt(Mojo::IOLoop-> stream($id )-> handle-> sockport, $last , ' different ports' );
143
-
144
- # HTTPS request with SOCKS proxy
145
- $ua -> proxy-> https(" socks://foo:bar\@ 127.0.0.1:$port " );
146
- $ua -> server-> url(' https' );
147
- $tx = $ua -> get(' /secure' );
148
- ok !$tx -> error, ' no error' ;
149
- ok !$tx -> kept_alive, ' kept connection not alive' ;
150
- ok $tx -> keep_alive, ' keep connection alive' ;
151
- is $tx -> res-> code, 200, ' right status' ;
152
- is $tx -> res-> body, " https:$last " , ' right content' ;
153
- isnt(Mojo::IOLoop-> stream($tx -> connection)-> handle-> sockport, $last , ' different ports' );
154
-
155
- # Disabled SOCKS proxy
156
- $ua -> server-> url(' http' );
157
- $ua -> proxy-> http(" socks://foo:baz\@ 127.0.0.1:$port " );
158
- $tx = $ua -> build_tx(GET => ' /' );
159
- $tx -> req-> via_proxy(0);
160
- $tx = $ua -> start($tx );
161
- ok !$tx -> error, ' no error' ;
162
- is $tx -> res-> code, 200, ' right status' ;
163
- is $tx -> res-> body, $tx -> local_port, ' right content' ;
102
+ subtest ' Failed authentication with SOCKS proxy' => sub {
103
+ my $ua = Mojo::UserAgent-> new(ioloop => Mojo::IOLoop-> singleton, insecure => 1);
104
+ $ua -> proxy-> http(" socks://foo:baz\@ 127.0.0.1:$port " );
105
+ my $tx = $ua -> get(' /' );
106
+ ok $tx -> error, ' has error' ;
107
+ };
108
+
109
+ subtest ' Simple request with SOCKS proxy' => sub {
110
+ my $ua = Mojo::UserAgent-> new(ioloop => Mojo::IOLoop-> singleton, insecure => 1);
111
+ $ua -> proxy-> http(" socks://foo:bar\@ 127.0.0.1:$port " );
112
+ my $tx = $ua -> get(' /' );
113
+ ok !$tx -> error, ' no error' ;
114
+ ok !$tx -> kept_alive, ' kept connection not alive' ;
115
+ ok $tx -> keep_alive, ' keep connection alive' ;
116
+ is $tx -> res-> code, 200, ' right status' ;
117
+ is $tx -> req-> headers-> proxy_authorization, undef , ' no "Proxy-Authorization" value' ;
118
+ is $tx -> res-> body, $last , ' right content' ;
119
+ isnt(Mojo::IOLoop-> stream($tx -> connection)-> handle-> sockport, $last , ' different ports' );
120
+ };
121
+
122
+ subtest ' Keep alive request with SOCKS proxy' => sub {
123
+ my $ua = Mojo::UserAgent-> new(ioloop => Mojo::IOLoop-> singleton, insecure => 1);
124
+ $ua -> proxy-> http(" socks://foo:bar\@ 127.0.0.1:$port " );
125
+ my $before = $last ;
126
+ my $tx = $ua -> get(' /' );
127
+ ok !$tx -> error, ' no error' ;
128
+ ok $tx -> kept_alive, ' kept connection alive' ;
129
+ ok $tx -> keep_alive, ' keep connection alive' ;
130
+ is $tx -> res-> code, 200, ' right status' ;
131
+ is $tx -> res-> body, $last , ' right content' ;
132
+ is $before , $last , ' same port' ;
133
+ isnt(Mojo::IOLoop-> stream($tx -> connection)-> handle-> sockport, $last , ' different ports' );
134
+ };
135
+
136
+ subtest ' WebSocket with SOCKS proxy' => sub {
137
+ my $ua = Mojo::UserAgent-> new(ioloop => Mojo::IOLoop-> singleton, insecure => 1);
138
+ $ua -> proxy-> http(" socks://foo:bar\@ 127.0.0.1:$port " );
139
+ my ($result , $id );
140
+ $ua -> websocket(
141
+ ' /echo' => sub {
142
+ my ($ua , $tx ) = @_ ;
143
+ $id = $tx -> connection;
144
+ $tx -> on(message => sub { $result = pop ; Mojo::IOLoop-> stop });
145
+ $tx -> send (' test' );
146
+ }
147
+ );
148
+ Mojo::IOLoop-> start;
149
+ is $result , $last , ' right result' ;
150
+ isnt(Mojo::IOLoop-> stream($id )-> handle-> sockport, $last , ' different ports' );
151
+ };
152
+
153
+ subtest ' HTTPS request with SOCKS proxy' => sub {
154
+ my $ua = Mojo::UserAgent-> new(ioloop => Mojo::IOLoop-> singleton, insecure => 1);
155
+ $ua -> proxy-> https(" socks://foo:bar\@ 127.0.0.1:$port " );
156
+ $ua -> server-> url(' https' );
157
+ my $tx = $ua -> get(' /secure' );
158
+ ok !$tx -> error, ' no error' ;
159
+ ok !$tx -> kept_alive, ' kept connection not alive' ;
160
+ ok $tx -> keep_alive, ' keep connection alive' ;
161
+ is $tx -> res-> code, 200, ' right status' ;
162
+ is $tx -> res-> body, " https:$last " , ' right content' ;
163
+ isnt(Mojo::IOLoop-> stream($tx -> connection)-> handle-> sockport, $last , ' different ports' );
164
+ };
165
+
166
+ subtest ' Disabled SOCKS proxy' => sub {
167
+ my $ua = Mojo::UserAgent-> new(ioloop => Mojo::IOLoop-> singleton, insecure => 1);
168
+ $ua -> server-> url(' http' );
169
+ $ua -> proxy-> http(" socks://foo:baz\@ 127.0.0.1:$port " );
170
+ my $tx = $ua -> build_tx(GET => ' /' );
171
+ $tx -> req-> via_proxy(0);
172
+ $tx = $ua -> start($tx );
173
+ ok !$tx -> error, ' no error' ;
174
+ is $tx -> res-> code, 200, ' right status' ;
175
+ is $tx -> res-> body, $tx -> local_port, ' right content' ;
176
+ };
164
177
165
178
done_testing();
0 commit comments