Skip to content

Commit b15e2f1

Browse files
authored
Remove CustomHeaders policy (#3172)
Resolves #3058
1 parent aded76e commit b15e2f1

File tree

6 files changed

+22
-96
lines changed

6 files changed

+22
-96
lines changed

sdk/core/azure_core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Breaking Changes
88

99
- Removed `constants` module.
10+
- Removed `CustomHeaders` policy.
1011

1112
### Bugs Fixed
1213

sdk/core/azure_core/src/http/pipeline.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ use typespec_client_core::http::{
2929
/// immediately.
3030
/// 2. User-specified per-call policies in [`ClientOptions::per_call_policies`] are executed.
3131
/// 3. The retry policy is executed. It allows to re-execute the following policies.
32-
/// 4. The policy that adds [`CustomHeaders`](crate::http::policies::CustomHeaders) is executed
33-
/// 5. Client library-specified per-retry policies. Per-retry polices are always executed at least once but are
32+
/// 4. Client library-specified per-retry policies. Per-retry polices are always executed at least once but are
3433
/// re-executed in case of retries.
35-
/// 6. User-specified per-retry policies in [`ClientOptions::per_try_policies`] are executed.
36-
/// 7. The transport policy is executed. Transport policy is always the last policy and is the policy that
34+
/// 5. User-specified per-retry policies in [`ClientOptions::per_try_policies`] are executed.
35+
/// 6. The transport policy is executed. Transport policy is always the last policy and is the policy that
3736
/// actually constructs the [`BufResponse`](http::BufResponse) to be passed up the pipeline.
3837
///
3938
/// A pipeline is immutable. In other words a policy can either succeed and call the following

sdk/typespec/typespec_client_core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
### Breaking Changes
88

9+
- Removed `CustomHeaders` policy.
10+
911
### Bugs Fixed
1012

1113
### Other Changes

sdk/typespec/typespec_client_core/src/http/pipeline.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use typespec::http::RawResponse;
55

66
use crate::http::{
7-
policies::{Buffer, CustomHeadersPolicy, LoggingPolicy, Policy, TransportPolicy},
7+
policies::{Buffer, LoggingPolicy, Policy, TransportPolicy},
88
BufResponse, ClientOptions, Context, PipelineOptions, Request,
99
};
1010
use 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

sdk/typespec/typespec_client_core/src/http/policies/custom_headers.rs

Lines changed: 0 additions & 80 deletions
This file was deleted.

sdk/typespec/typespec_client_core/src/http/policies/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ use crate::http::{BufResponse, Context, Request};
77
use async_trait::async_trait;
88
use std::sync::Arc;
99

10-
mod custom_headers;
1110
mod logging;
1211
mod retry;
1312
mod transport;
1413

15-
pub use custom_headers::*;
1614
pub(crate) use logging::*;
1715
pub use retry::*;
1816
pub use transport::*;

0 commit comments

Comments
 (0)