4
4
use typespec:: http:: RawResponse ;
5
5
6
6
use crate :: http:: {
7
- policies:: { Buffer , CustomHeadersPolicy , LoggingPolicy , Policy , TransportPolicy } ,
7
+ policies:: { Buffer , LoggingPolicy , Policy , TransportPolicy } ,
8
8
BufResponse , ClientOptions , Context , PipelineOptions , Request ,
9
9
} ;
10
10
use std:: sync:: Arc ;
@@ -17,11 +17,10 @@ use std::sync::Arc;
17
17
/// immediately.
18
18
/// 2. User-specified per-call policies in [`ClientOptions::per_call_policies`] are executed.
19
19
/// 3. The retry policy is executed. It allows to re-execute the following policies.
20
- /// 4. The policy that adds [`CustomHeaders`](crate::http::policies::CustomHeaders) is executed
21
- /// 5. Client library-specified per-retry policies. Per-retry polices are always executed at least once but are
20
+ /// 4. Client library-specified per-retry policies. Per-retry polices are always executed at least once but are
22
21
/// re-executed in case of retries.
23
- /// 6 . User-specified per-retry policies in [`ClientOptions::per_try_policies`] are executed.
24
- /// 7 . The transport policy is executed. Transport policy is always the last policy and is the policy that
22
+ /// 5 . User-specified per-retry policies in [`ClientOptions::per_try_policies`] are executed.
23
+ /// 6 . The transport policy is executed. Transport policy is always the last policy and is the policy that
25
24
/// actually constructs the [`BufResponse`] to be passed up the pipeline.
26
25
///
27
26
/// A pipeline is immutable. In other words a policy can either succeed and call the following
@@ -56,14 +55,19 @@ impl Pipeline {
56
55
per_try_policies : Vec < Arc < dyn Policy > > ,
57
56
pipeline_options : Option < PipelineOptions > ,
58
57
) -> Self {
58
+ // The number of policies we'll push to the pipeline Vec ourselves.
59
+ const BUILT_IN_LEN : usize = 3 ;
59
60
let mut pipeline: Vec < Arc < dyn Policy > > = Vec :: with_capacity (
60
- options. per_call_policies . len ( )
61
- + per_call_policies. len ( )
62
- + options. per_try_policies . len ( )
61
+ per_call_policies. len ( )
62
+ + options. per_call_policies . len ( )
63
63
+ per_try_policies. len ( )
64
- + 3 ,
64
+ + options. per_try_policies . len ( )
65
+ + BUILT_IN_LEN ,
65
66
) ;
66
67
68
+ #[ cfg( debug_assertions) ]
69
+ let initial_capacity = pipeline. capacity ( ) ;
70
+
67
71
pipeline. extend_from_slice ( & per_call_policies) ;
68
72
pipeline. extend_from_slice ( & options. per_call_policies ) ;
69
73
@@ -72,7 +76,6 @@ impl Pipeline {
72
76
let retry_policy = options. retry . to_policy ( pipeline_options. retry_headers ) ;
73
77
pipeline. push ( retry_policy) ;
74
78
75
- pipeline. push ( Arc :: new ( CustomHeadersPolicy :: default ( ) ) ) ;
76
79
pipeline. push ( Arc :: new ( LoggingPolicy :: new ( options. logging ) ) ) ;
77
80
78
81
pipeline. extend_from_slice ( & per_try_policies) ;
@@ -82,6 +85,9 @@ impl Pipeline {
82
85
Arc :: new ( TransportPolicy :: new ( options. transport . unwrap_or_default ( ) ) ) ;
83
86
pipeline. push ( transport) ;
84
87
88
+ // Make sure we didn't have to resize the Vec.
89
+ debug_assert_eq ! ( pipeline. len( ) , initial_capacity) ;
90
+
85
91
Self { pipeline }
86
92
}
87
93
0 commit comments