@@ -42,6 +42,7 @@ pub mod compat;
42
42
pub struct Client < C , B = proto:: Body > {
43
43
connector : C ,
44
44
executor : Exec ,
45
+ h1_writev : bool ,
45
46
pool : Pool < HyperClient < B > > ,
46
47
}
47
48
@@ -96,6 +97,7 @@ impl<C, B> Client<C, B> {
96
97
Client {
97
98
connector : config. connector ,
98
99
executor : exec,
100
+ h1_writev : config. h1_writev ,
99
101
pool : Pool :: new ( config. keep_alive , config. keep_alive_timeout )
100
102
}
101
103
}
@@ -197,6 +199,7 @@ where C: Connect,
197
199
let executor = self . executor . clone ( ) ;
198
200
let pool = self . pool . clone ( ) ;
199
201
let pool_key = Rc :: new ( domain. to_string ( ) ) ;
202
+ let h1_writev = self . h1_writev ;
200
203
self . connector . connect ( url)
201
204
. and_then ( move |io| {
202
205
let ( tx, rx) = dispatch:: channel ( ) ;
@@ -205,7 +208,10 @@ where C: Connect,
205
208
should_close : Cell :: new ( true ) ,
206
209
} ;
207
210
let pooled = pool. pooled ( pool_key, tx) ;
208
- let conn = proto:: Conn :: < _ , _ , proto:: ClientTransaction , _ > :: new ( io, pooled. clone ( ) ) ;
211
+ let mut conn = proto:: Conn :: < _ , _ , proto:: ClientTransaction , _ > :: new ( io, pooled. clone ( ) ) ;
212
+ if !h1_writev {
213
+ conn. set_write_strategy_flatten ( ) ;
214
+ }
209
215
let dispatch = proto:: dispatch:: Dispatcher :: new ( proto:: dispatch:: Client :: new ( rx) , conn) ;
210
216
executor. execute ( dispatch. map_err ( |e| debug ! ( "client connection error: {}" , e) ) ) ?;
211
217
Ok ( pooled)
@@ -256,6 +262,7 @@ impl<C: Clone, B> Clone for Client<C, B> {
256
262
Client {
257
263
connector : self . connector . clone ( ) ,
258
264
executor : self . executor . clone ( ) ,
265
+ h1_writev : self . h1_writev ,
259
266
pool : self . pool . clone ( ) ,
260
267
}
261
268
}
@@ -307,9 +314,9 @@ pub struct Config<C, B> {
307
314
connector : C ,
308
315
keep_alive : bool ,
309
316
keep_alive_timeout : Option < Duration > ,
317
+ h1_writev : bool ,
310
318
//TODO: make use of max_idle config
311
319
max_idle : usize ,
312
- no_proto : bool ,
313
320
}
314
321
315
322
/// Phantom type used to signal that `Config` should create a `HttpConnector`.
@@ -324,8 +331,8 @@ impl Default for Config<UseDefaultConnector, proto::Body> {
324
331
connector : UseDefaultConnector ( ( ) ) ,
325
332
keep_alive : true ,
326
333
keep_alive_timeout : Some ( Duration :: from_secs ( 90 ) ) ,
334
+ h1_writev : true ,
327
335
max_idle : 5 ,
328
- no_proto : false ,
329
336
}
330
337
}
331
338
}
@@ -348,8 +355,8 @@ impl<C, B> Config<C, B> {
348
355
connector : self . connector ,
349
356
keep_alive : self . keep_alive ,
350
357
keep_alive_timeout : self . keep_alive_timeout ,
358
+ h1_writev : self . h1_writev ,
351
359
max_idle : self . max_idle ,
352
- no_proto : self . no_proto ,
353
360
}
354
361
}
355
362
@@ -362,8 +369,8 @@ impl<C, B> Config<C, B> {
362
369
connector : val,
363
370
keep_alive : self . keep_alive ,
364
371
keep_alive_timeout : self . keep_alive_timeout ,
372
+ h1_writev : self . h1_writev ,
365
373
max_idle : self . max_idle ,
366
- no_proto : self . no_proto ,
367
374
}
368
375
}
369
376
@@ -398,6 +405,20 @@ impl<C, B> Config<C, B> {
398
405
}
399
406
*/
400
407
408
+ /// Set whether HTTP/1 connections should try to use vectored writes,
409
+ /// or always flatten into a single buffer.
410
+ ///
411
+ /// Note that setting this to false may mean more copies of body data,
412
+ /// but may also improve performance when an IO transport doesn't
413
+ /// support vectored writes well, such as most TLS implementations.
414
+ ///
415
+ /// Default is true.
416
+ #[ inline]
417
+ pub fn http1_writev ( mut self , val : bool ) -> Config < C , B > {
418
+ self . h1_writev = val;
419
+ self
420
+ }
421
+
401
422
#[ doc( hidden) ]
402
423
#[ deprecated( since="0.11.11" , note="no_proto is always enabled" ) ]
403
424
pub fn no_proto ( self ) -> Config < C , B > {
@@ -444,6 +465,7 @@ impl<C, B> fmt::Debug for Config<C, B> {
444
465
f. debug_struct ( "Config" )
445
466
. field ( "keep_alive" , & self . keep_alive )
446
467
. field ( "keep_alive_timeout" , & self . keep_alive_timeout )
468
+ . field ( "http1_writev" , & self . h1_writev )
447
469
. field ( "max_idle" , & self . max_idle )
448
470
. finish ( )
449
471
}
0 commit comments