Skip to content

Commit 5c708e3

Browse files
Removed Azure specific headers from typespec_client_core. (Azure#2958)
Co-authored-by: Copilot <[email protected]>
1 parent bbfd1b0 commit 5c708e3

File tree

38 files changed

+515
-533
lines changed

38 files changed

+515
-533
lines changed

Cargo.lock

Lines changed: 21 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/core/azure_core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Removed feature `reqwest_rustls_tls`. See [README.md](https://github.com/heaths/azure-sdk-for-rust/blob/main/sdk/core/azure_core/README.md) for alternative HTTP client configuration.
1919
- Removed the `fs` module including the `FileStream` and `FileStreamBuilder` types. Moved to `examples/` for `typespec_client_core` to copy if needed.
2020
- Removed the `setters` macro.
21+
- Added the ability to configure pipeline configuration independently from `ClientOptions`. This adds a new optional `PipelineOptions` parameter to `azure_core::http::Pipeline::new()`. If not specified, it defaults to the expected options for `azure_core` services.
2122

2223
### Bugs Fixed
2324

sdk/core/azure_core/benches/http_transport_benchmarks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl TestServiceClient {
6666
options.client_options,
6767
Vec::default(),
6868
Vec::default(),
69+
None,
6970
),
7071
})
7172
}

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

Lines changed: 33 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -10,81 +10,48 @@ pub use typespec_client_core::http::headers::*;
1010
// We use lowercase below for simple comparisons downstream.
1111

1212
pub const ACCOUNT_KIND: HeaderName = HeaderName::from_static("x-ms-account-kind");
13-
pub const ACL: HeaderName = HeaderName::from_static("x-ms-acl");
14-
pub const ACTIVITY_ID: HeaderName = HeaderName::from_static("x-ms-activity-id");
15-
pub const APP: HeaderName = HeaderName::from_static("x-ms-app");
13+
pub(crate) const ACTIVITY_ID: HeaderName = HeaderName::from_static("x-ms-activity-id");
14+
pub(crate) const APP: HeaderName = HeaderName::from_static("x-ms-app");
1615
pub const APPEND_POSITION: HeaderName = HeaderName::from_static("x-ms-blob-condition-appendpos"); // cspell:ignore appendpos
1716
pub const AZURE_ASYNCOPERATION: HeaderName = HeaderName::from_static("azure-asyncoperation");
18-
pub const BLOB_ACCESS_TIER: HeaderName = HeaderName::from_static("x-ms-access-tier");
19-
pub const BLOB_CACHE_CONTROL: HeaderName = HeaderName::from_static("x-ms-blob-cache-control");
20-
pub const BLOB_COMMITTED_BLOCK_COUNT: HeaderName =
21-
HeaderName::from_static("x-ms-blob-committed-block-count");
22-
pub const BLOB_CONTENT_LENGTH: HeaderName = HeaderName::from_static("x-ms-blob-content-length");
23-
pub const BLOB_PUBLIC_ACCESS: HeaderName = HeaderName::from_static("x-ms-blob-public-access");
24-
pub const BLOB_SEQUENCE_NUMBER: HeaderName = HeaderName::from_static("x-ms-blob-sequence-number");
25-
pub const BLOB_TYPE: HeaderName = HeaderName::from_static("x-ms-blob-type");
17+
pub(crate) const BLOB_SEQUENCE_NUMBER: HeaderName =
18+
HeaderName::from_static("x-ms-blob-sequence-number");
2619
pub const CLIENT_REQUEST_ID: HeaderName = HeaderName::from_static("x-ms-client-request-id");
27-
pub const CLIENT_VERSION: HeaderName = HeaderName::from_static("x-ms-client-version");
28-
pub const CONTENT_DISPOSITION: HeaderName =
20+
pub(crate) const CLIENT_VERSION: HeaderName = HeaderName::from_static("x-ms-client-version");
21+
pub(crate) const CONTENT_DISPOSITION: HeaderName =
2922
HeaderName::from_static("x-ms-blob-content-disposition");
30-
pub const CONTINUATION: HeaderName = HeaderName::from_static("x-ms-continuation");
31-
pub const COPY_COMPLETION_TIME: HeaderName = HeaderName::from_static("x-ms-copy-completion-time");
32-
pub const COPY_PROGRESS: HeaderName = HeaderName::from_static("x-ms-copy-progress");
33-
pub const COPY_SOURCE: HeaderName = HeaderName::from_static("x-ms-copy-source");
34-
pub const COPY_STATUS_DESCRIPTION: HeaderName =
35-
HeaderName::from_static("x-ms-copy-status-description");
36-
pub const COPY_STATUS: HeaderName = HeaderName::from_static("x-ms-copy-status");
37-
pub const CREATION_TIME: HeaderName = HeaderName::from_static("x-ms-creation-time");
38-
pub const DELETE_SNAPSHOTS: HeaderName = HeaderName::from_static("x-ms-delete-snapshots");
39-
pub const DELETE_TYPE_PERMANENT: HeaderName = HeaderName::from_static("x-ms-delete-type-permanent");
40-
pub const ENCRYPTION_ALGORITHM: HeaderName = HeaderName::from_static("x-ms-encryption-algorithm");
41-
pub const ENCRYPTION_KEY_SHA256: HeaderName = HeaderName::from_static("x-ms-encryption-key-sha256");
42-
pub const ENCRYPTION_KEY: HeaderName = HeaderName::from_static("x-ms-encryption-key");
43-
pub const HAS_IMMUTABILITY_POLICY: HeaderName =
44-
HeaderName::from_static("x-ms-has-immutability-policy");
45-
pub const HAS_LEGAL_HOLD: HeaderName = HeaderName::from_static("x-ms-has-legal-hold");
46-
pub const IF_SEQUENCE_NUMBER_EQ: HeaderName = HeaderName::from_static("x-ms-if-sequence-number-eq");
47-
pub const IF_SEQUENCE_NUMBER_LE: HeaderName = HeaderName::from_static("x-ms-if-sequence-number-le");
48-
pub const IF_SEQUENCE_NUMBER_LT: HeaderName = HeaderName::from_static("x-ms-if-sequence-number-lt");
49-
pub const IF_TAGS: HeaderName = HeaderName::from_static("x-ms-if-tags");
50-
pub const ITEM_COUNT: HeaderName = HeaderName::from_static("x-ms-item-count");
51-
pub const ITEM_TYPE: HeaderName = HeaderName::from_static("x-ms-item-type");
52-
pub const LEASE_ACTION: HeaderName = HeaderName::from_static("x-ms-lease-action");
53-
pub const LEASE_BREAK_PERIOD: HeaderName = HeaderName::from_static("x-ms-lease-break-period");
54-
pub const LEASE_DURATION: HeaderName = HeaderName::from_static("x-ms-lease-duration");
55-
pub const LEASE_ID: HeaderName = HeaderName::from_static("x-ms-lease-id");
56-
pub const LEASE_STATE: HeaderName = HeaderName::from_static("x-ms-lease-state");
57-
pub const LEASE_STATUS: HeaderName = HeaderName::from_static("x-ms-lease-status");
58-
pub const LEASE_TIME: HeaderName = HeaderName::from_static("x-ms-lease-time");
59-
pub const MAX_ITEM_COUNT: HeaderName = HeaderName::from_static("x-ms-max-item-count");
60-
pub const META_PREFIX: HeaderName = HeaderName::from_static("x-ms-meta-");
23+
pub(crate) const CONTINUATION: HeaderName = HeaderName::from_static("x-ms-continuation");
24+
pub const ERROR_CODE: HeaderName = HeaderName::from_static("x-ms-error-code");
25+
pub(crate) const IF_SEQUENCE_NUMBER_EQ: HeaderName =
26+
HeaderName::from_static("x-ms-if-sequence-number-eq");
27+
pub(crate) const IF_SEQUENCE_NUMBER_LE: HeaderName =
28+
HeaderName::from_static("x-ms-if-sequence-number-le");
29+
pub(crate) const IF_SEQUENCE_NUMBER_LT: HeaderName =
30+
HeaderName::from_static("x-ms-if-sequence-number-lt");
31+
pub(crate) const IF_TAGS: HeaderName = HeaderName::from_static("x-ms-if-tags");
32+
pub(crate) const LEASE_BREAK_PERIOD: HeaderName =
33+
HeaderName::from_static("x-ms-lease-break-period");
34+
pub(crate) const LEASE_DURATION: HeaderName = HeaderName::from_static("x-ms-lease-duration");
35+
pub(crate) const LEASE_ID: HeaderName = HeaderName::from_static("x-ms-lease-id");
36+
pub(crate) const MAX_ITEM_COUNT: HeaderName = HeaderName::from_static("x-ms-max-item-count");
6137
pub const MS_DATE: HeaderName = HeaderName::from_static("x-ms-date");
62-
pub const MS_RANGE: HeaderName = HeaderName::from_static("x-ms-range");
63-
pub const NAMESPACE_ENABLED: HeaderName = HeaderName::from_static("x-ms-namespace-enabled");
64-
pub const PAGE_WRITE: HeaderName = HeaderName::from_static("x-ms-page-write");
65-
pub const PROPERTIES: HeaderName = HeaderName::from_static("x-ms-properties");
66-
pub const PROPOSED_LEASE_ID: HeaderName = HeaderName::from_static("x-ms-proposed-lease-id");
67-
pub const RANGE_GET_CONTENT_CRC64: HeaderName =
38+
pub(crate) const MS_RANGE: HeaderName = HeaderName::from_static("x-ms-range");
39+
pub(crate) const PROPOSED_LEASE_ID: HeaderName = HeaderName::from_static("x-ms-proposed-lease-id");
40+
pub(crate) const RANGE_GET_CONTENT_CRC64: HeaderName =
6841
HeaderName::from_static("x-ms-range-get-content-crc64");
69-
pub const RANGE_GET_CONTENT_MD5: HeaderName = HeaderName::from_static("x-ms-range-get-content-md5");
70-
pub const REQUEST_ID: HeaderName = HeaderName::from_static("x-ms-request-id");
71-
pub const REQUEST_SERVER_ENCRYPTED: HeaderName =
72-
HeaderName::from_static("x-ms-request-server-encrypted");
73-
pub const REQUIRES_SYNC: HeaderName = HeaderName::from_static("x-ms-requires-sync");
74-
pub const SERVER_ENCRYPTED: HeaderName = HeaderName::from_static("x-ms-server-encrypted");
75-
pub const SESSION_TOKEN: HeaderName = HeaderName::from_static("x-ms-session-token");
76-
pub const SKU_NAME: HeaderName = HeaderName::from_static("x-ms-sku-name");
77-
pub const SOURCE_IF_MATCH: HeaderName = HeaderName::from_static("x-ms-source-if-match");
78-
pub const SOURCE_IF_MODIFIED_SINCE: HeaderName =
42+
pub(crate) const REQUEST_ID: HeaderName = HeaderName::from_static("x-ms-request-id");
43+
pub const RETRY_AFTER_MS: HeaderName = HeaderName::from_static("retry-after-ms");
44+
pub(crate) const SOURCE_IF_MATCH: HeaderName = HeaderName::from_static("x-ms-source-if-match");
45+
pub(crate) const SOURCE_IF_MODIFIED_SINCE: HeaderName =
7946
HeaderName::from_static("x-ms-source-if-modified-since");
80-
pub const SOURCE_IF_NONE_MATCH: HeaderName = HeaderName::from_static("x-ms-source-if-none-match");
81-
pub const SOURCE_IF_UNMODIFIED_SINCE: HeaderName =
47+
pub(crate) const SOURCE_IF_NONE_MATCH: HeaderName =
48+
HeaderName::from_static("x-ms-source-if-none-match");
49+
pub(crate) const SOURCE_IF_UNMODIFIED_SINCE: HeaderName =
8250
HeaderName::from_static("x-ms-source-if-unmodified-since");
83-
pub const SOURCE_LEASE_ID: HeaderName = HeaderName::from_static("x-ms-source-lease-id");
84-
pub const SOURCE_RANGE: HeaderName = HeaderName::from_static("x-ms-source-range");
85-
pub const TAGS: HeaderName = HeaderName::from_static("x-ms-tags");
86-
pub const USER: HeaderName = HeaderName::from_static("x-ms-user");
51+
pub(crate) const SOURCE_LEASE_ID: HeaderName = HeaderName::from_static("x-ms-source-lease-id");
52+
pub(crate) const USER: HeaderName = HeaderName::from_static("x-ms-user");
8753
pub const VERSION: HeaderName = HeaderName::from_static("x-ms-version");
54+
pub const X_MS_RETRY_AFTER_MS: HeaderName = HeaderName::from_static("x-ms-retry-after-ms");
8855

8956
/// Constants related to the Content-Type header
9057
///
@@ -95,15 +62,8 @@ pub mod content_type {
9562
// Form content types
9663
// https://www.w3.org/TR/html401/interact/forms.html#h-17.13.4
9764

98-
pub const MULTIPART_FORM_DATA: HeaderValue = HeaderValue::from_static("multipart/form-data");
9965
pub const APPLICATION_X_WWW_FORM_URLENCODED: HeaderValue =
10066
HeaderValue::from_static("application/x-www-form-urlencoded");
101-
102-
pub const APPLICATION_XML: HeaderValue = HeaderValue::from_static("application/xml");
103-
pub const APPLICATION_JSON: HeaderValue = HeaderValue::from_static("application/json");
104-
pub const APPLICATION_OCTET_STREAM: HeaderValue =
105-
HeaderValue::from_static("application/octet-stream");
106-
pub const TEXT_PLAIN: HeaderValue = HeaderValue::from_static("text/plain");
10767
}
10868

10969
/// Constants related to query parameters

sdk/core/azure_core/src/http/options/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ pub use instrumentation::*;
88
use std::sync::Arc;
99
use typespec_client_core::http::policies::Policy;
1010
pub use typespec_client_core::http::{
11-
ClientMethodOptions, ExponentialRetryOptions, FixedRetryOptions, LoggingOptions, RetryOptions,
12-
TransportOptions,
11+
ClientMethodOptions, ExponentialRetryOptions, FixedRetryOptions, LoggingOptions,
12+
PipelineOptions, RetryOptions, TransportOptions,
1313
};
1414
pub use user_agent::*;
1515

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use super::policies::ClientRequestIdPolicy;
55
use crate::http::{
6+
headers::{ERROR_CODE, RETRY_AFTER_MS, X_MS_RETRY_AFTER_MS},
67
policies::{
78
Policy, PublicApiInstrumentationPolicy, RequestInstrumentationPolicy, UserAgentPolicy,
89
},
@@ -13,7 +14,9 @@ use std::{
1314
ops::Deref,
1415
sync::Arc,
1516
};
16-
use typespec_client_core::http;
17+
use typespec_client_core::http::{
18+
self, headers::RETRY_AFTER, policies::RetryHeaders, PipelineOptions,
19+
};
1720

1821
/// Execution pipeline.
1922
///
@@ -43,12 +46,21 @@ impl Pipeline {
4346
///
4447
/// Crates can simply pass `option_env!("CARGO_PKG_NAME")` and `option_env!("CARGO_PKG_VERSION")` for the
4548
/// `crate_name` and `crate_version` arguments respectively.
49+
///
50+
/// # Arguments
51+
/// * `crate_name` - The name of the crate implementing the client library.
52+
/// * `crate_version` - The version of the crate implementing the client library.
53+
/// * `options` - The client options.
54+
/// * `per_call_policies` - Policies to be executed per call, before the policies in `ClientOptions::per_call_policies`.
55+
/// * `per_try_policies` - Policies to be executed per try, before the policies in `ClientOptions::per_try_policies`.
56+
/// * `pipeline_options` - Additional options for the pipeline. If `None`, default options will be used.
4657
pub fn new(
4758
crate_name: Option<&'static str>,
4859
crate_version: Option<&'static str>,
4960
options: ClientOptions,
5061
per_call_policies: Vec<Arc<dyn Policy>>,
5162
per_try_policies: Vec<Arc<dyn Policy>>,
63+
pipeline_options: Option<PipelineOptions>,
5264
) -> Self {
5365
let (core_client_options, options) = options.deconstruct();
5466

@@ -91,10 +103,18 @@ impl Pipeline {
91103
push_unique(&mut per_try_policies, request_instrumentation_policy);
92104
}
93105

106+
let pipeline_options = pipeline_options.unwrap_or_else(|| PipelineOptions {
107+
retry_headers: RetryHeaders {
108+
retry_headers: vec![X_MS_RETRY_AFTER_MS, RETRY_AFTER_MS, RETRY_AFTER],
109+
error_header: Some(ERROR_CODE),
110+
},
111+
});
112+
94113
Self(http::Pipeline::new(
95114
options,
96115
per_call_policies,
97116
per_try_policies,
117+
Some(pipeline_options),
98118
))
99119
}
100120
}
@@ -179,6 +199,7 @@ mod tests {
179199
options,
180200
per_call_policies,
181201
per_retry_policies,
202+
None,
182203
);
183204

184205
let mut request = Request::new("https://example.com".parse().unwrap(), Method::Get);
@@ -232,6 +253,7 @@ mod tests {
232253
options,
233254
per_call_policies,
234255
per_retry_policies,
256+
None,
235257
);
236258

237259
let mut request = Request::new("https://example.com".parse().unwrap(), Method::Get);
@@ -285,6 +307,7 @@ mod tests {
285307
options,
286308
per_call_policies,
287309
per_retry_policies,
310+
None,
288311
);
289312

290313
let mut request = Request::new("https://example.com".parse().unwrap(), Method::Get);
@@ -345,6 +368,7 @@ mod tests {
345368
options,
346369
per_call_policies,
347370
per_retry_policies,
371+
None,
348372
);
349373

350374
let mut request = Request::new("https://example.com".parse().unwrap(), Method::Get);

0 commit comments

Comments
 (0)