@@ -66,6 +66,7 @@ pub struct PProxyHandle {
66
66
pub enum FullLength {
67
67
NotParsed ,
68
68
NotSet ,
69
+ Chunked ,
69
70
Parsed ( usize ) ,
70
71
}
71
72
@@ -74,8 +75,8 @@ impl FullLength {
74
75
matches ! ( self , FullLength :: NotParsed )
75
76
}
76
77
77
- pub fn not_set ( & self ) -> bool {
78
- matches ! ( self , FullLength :: NotSet )
78
+ pub fn chunked ( & self ) -> bool {
79
+ matches ! ( self , FullLength :: Chunked )
79
80
}
80
81
}
81
82
@@ -139,7 +140,7 @@ impl PProxy {
139
140
return Err ( Error :: IncompleteHttpRequest ) ;
140
141
}
141
142
142
- let mut stream = tcp_connect_with_timeout ( & proxy_addr, 1 ) . await ?;
143
+ let mut stream = tcp_connect_with_timeout ( & proxy_addr, 2 ) . await ?;
143
144
stream. write_all ( request) . await ?;
144
145
145
146
let mut response = Vec :: new ( ) ;
@@ -149,7 +150,7 @@ impl PProxy {
149
150
let mut buf = [ 0u8 ; 30000 ] ;
150
151
151
152
let Ok ( Ok ( n) ) =
152
- timeout ( std:: time:: Duration :: from_secs ( 5 ) , stream. read ( & mut buf) ) . await
153
+ timeout ( std:: time:: Duration :: from_secs ( 2 ) , stream. read ( & mut buf) ) . await
153
154
else {
154
155
break ;
155
156
} ;
@@ -175,12 +176,25 @@ impl PProxy {
175
176
value. parse :: < usize > ( ) . ok ( )
176
177
} ) ;
177
178
178
- match content_length {
179
- Some ( content_length) => {
179
+ let transfor_encoding = resp_checker. headers . iter ( ) . find_map ( |h| {
180
+ if h. name . to_lowercase ( ) != "transfer-encoding" {
181
+ return None ;
182
+ }
183
+ let Ok ( value) = std:: str:: from_utf8 ( h. value ) else {
184
+ return None ;
185
+ } ;
186
+ Some ( value)
187
+ } ) ;
188
+
189
+ match ( content_length, transfor_encoding) {
190
+ ( Some ( content_length) , _) => {
180
191
let header_length = res. unwrap ( ) ;
181
192
full_length = FullLength :: Parsed ( header_length + content_length)
182
193
}
183
- None => {
194
+ ( None , Some ( value) ) if value. to_lowercase ( ) . contains ( "chunked" ) => {
195
+ full_length = FullLength :: Chunked ;
196
+ }
197
+ _ => {
184
198
full_length = FullLength :: NotSet ;
185
199
}
186
200
}
@@ -192,6 +206,10 @@ impl PProxy {
192
206
break ;
193
207
}
194
208
}
209
+
210
+ if full_length. chunked ( ) && response. ends_with ( b"0\r \n \r \n " ) {
211
+ break ;
212
+ }
195
213
}
196
214
197
215
if response. is_empty ( ) {
0 commit comments