44use typespec:: http:: RawResponse ;
55
66use crate :: http:: {
7- policies:: { Buffer , CustomHeadersPolicy , LoggingPolicy , Policy , TransportPolicy } ,
7+ policies:: { Buffer , LoggingPolicy , Policy , TransportPolicy } ,
88 BufResponse , ClientOptions , Context , PipelineOptions , Request ,
99} ;
1010use std:: sync:: Arc ;
@@ -17,11 +17,10 @@ use std::sync::Arc;
1717/// immediately.
1818/// 2. User-specified per-call policies in [`ClientOptions::per_call_policies`] are executed.
1919/// 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
2221/// 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
2524/// actually constructs the [`BufResponse`] to be passed up the pipeline.
2625///
2726/// A pipeline is immutable. In other words a policy can either succeed and call the following
@@ -56,14 +55,19 @@ impl Pipeline {
5655 per_try_policies : Vec < Arc < dyn Policy > > ,
5756 pipeline_options : Option < PipelineOptions > ,
5857 ) -> Self {
58+ // The number of policies we'll push to the pipeline Vec ourselves.
59+ const BUILT_IN_LEN : usize = 3 ;
5960 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 ( )
6363 + per_try_policies. len ( )
64- + 3 ,
64+ + options. per_try_policies . len ( )
65+ + BUILT_IN_LEN ,
6566 ) ;
6667
68+ #[ cfg( debug_assertions) ]
69+ let initial_capacity = pipeline. capacity ( ) ;
70+
6771 pipeline. extend_from_slice ( & per_call_policies) ;
6872 pipeline. extend_from_slice ( & options. per_call_policies ) ;
6973
@@ -72,7 +76,6 @@ impl Pipeline {
7276 let retry_policy = options. retry . to_policy ( pipeline_options. retry_headers ) ;
7377 pipeline. push ( retry_policy) ;
7478
75- pipeline. push ( Arc :: new ( CustomHeadersPolicy :: default ( ) ) ) ;
7679 pipeline. push ( Arc :: new ( LoggingPolicy :: new ( options. logging ) ) ) ;
7780
7881 pipeline. extend_from_slice ( & per_try_policies) ;
@@ -82,6 +85,9 @@ impl Pipeline {
8285 Arc :: new ( TransportPolicy :: new ( options. transport . unwrap_or_default ( ) ) ) ;
8386 pipeline. push ( transport) ;
8487
88+ // Make sure we didn't have to resize the Vec.
89+ debug_assert_eq ! ( pipeline. len( ) , initial_capacity) ;
90+
8591 Self { pipeline }
8692 }
8793
0 commit comments