Skip to content

Commit 811cb15

Browse files
authored
Redefine Method, StatusCode from http_types in typespec (#2331)
* Redefine Method, StatusCode from http_types in typespec Resolves #1644 and replaces #2233. The latter PR was a good attempt but we decided internally we don't want to take a dependency on a different crate - `http` ; though, we do have a transitive dependency on it already - for something so simple. This starts as a copy from http_types with appropriate attribution. We may want to remove a bunch of Methods we don't need, though, at some point. * Change StatusCode to extensible enum * Fix lint * Remove unnecessary HTTP methods for Azure services
1 parent 8387180 commit 811cb15

File tree

18 files changed

+1159
-459
lines changed

18 files changed

+1159
-459
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ flate2 = "1.1.0"
8989
futures = "0.3"
9090
getrandom = { version = "0.2", features = ["js"] }
9191
hmac = { version = "0.12" }
92-
http-types = { version = "2.12", default-features = false }
9392
litemap = "0.7.4"
9493
log = "0.4"
9594
oauth2 = { version = "5.0.0", default-features = false }

NOTICE.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,31 @@ In the event that we accidentally failed to list a required notice, please
2727
bring it to our attention. Post an issue.
2828

2929
The attached notices are provided for information only.
30+
31+
License notice for `http_types::{Method, StatusCode}`
32+
------------------------------------------------------------------------------
33+
34+
The MIT License (MIT)
35+
36+
Copyright (c) 2019 Yoshua Wuyts
37+
Copyright (c) 2017 http-rs authors
38+
Copyright (c) 2020 Jacob Brown
39+
Copyright (c) 2016-2018 Michael Tilli (Pyfisch) & `httpdate` contributors
40+
41+
Permission is hereby granted, free of charge, to any person obtaining a copy
42+
of this software and associated documentation files (the "Software"), to deal
43+
in the Software without restriction, including without limitation the rights
44+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
45+
copies of the Software, and to permit persons to whom the Software is
46+
furnished to do so, subject to the following conditions:
47+
48+
The above copyright notice and this permission notice shall be included in all
49+
copies or substantial portions of the Software.
50+
51+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
52+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
53+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
54+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
55+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
56+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
57+
SOFTWARE.

sdk/core/azure_core_amqp/src/fe2o3/management.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,7 @@ impl TryFrom<fe2o3_amqp_management::error::Error> for AmqpError {
137137

138138
fe2o3_amqp_management::error::Error::Status(s) => {
139139
Ok(AmqpError::from(AmqpErrorKind::ManagementStatusCode(
140-
azure_core::StatusCode::try_from(s.code.0.get()).map_err(|_| {
141-
azure_core::Error::message(
142-
azure_core::error::ErrorKind::DataConversion,
143-
format!("invalid status code {s}"),
144-
)
145-
})?,
140+
azure_core::StatusCode::from(s.code.0.get()),
146141
s.description.clone(),
147142
)))
148143
}

sdk/cosmos/azure_data_cosmos/src/pipeline/signature_target.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ impl<'a> SignatureTarget<'a> {
5454
azure_core::Method::Post => "post",
5555
azure_core::Method::Delete => "delete",
5656
azure_core::Method::Head => "head",
57-
azure_core::Method::Trace => "trace",
58-
azure_core::Method::Options => "options",
59-
azure_core::Method::Connect => "connect",
6057
azure_core::Method::Patch => "patch",
6158
_ => "extension",
6259
},

sdk/identity/azure_identity/src/oauth2_http_client.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ fn try_from_method(method: &oauth2::http::Method) -> azure_core::Result<azure_co
6060
oauth2::http::Method::PUT => Ok(azure_core::Method::Put),
6161
oauth2::http::Method::DELETE => Ok(azure_core::Method::Delete),
6262
oauth2::http::Method::HEAD => Ok(azure_core::Method::Head),
63-
oauth2::http::Method::OPTIONS => Ok(azure_core::Method::Options),
64-
oauth2::http::Method::CONNECT => Ok(azure_core::Method::Connect),
6563
oauth2::http::Method::PATCH => Ok(azure_core::Method::Patch),
66-
oauth2::http::Method::TRACE => Ok(azure_core::Method::Trace),
6764
_ => Err(Error::with_message(ErrorKind::DataConversion, || {
6865
format!("unsupported oauth2::http::Method {method}")
6966
})),
@@ -93,7 +90,7 @@ fn try_from_headers(
9390
}
9491

9592
fn try_from_status(status: azure_core::StatusCode) -> azure_core::Result<oauth2::http::StatusCode> {
96-
oauth2::http::StatusCode::from_u16(status as u16).map_kind(ErrorKind::DataConversion)
93+
oauth2::http::StatusCode::from_u16(*status).map_kind(ErrorKind::DataConversion)
9794
}
9895

9996
fn to_headers(map: &oauth2::http::header::HeaderMap) -> azure_core::headers::Headers {

sdk/typespec/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ keywords = ["typespec"]
1313

1414
[dependencies]
1515
base64.workspace = true
16-
http-types = { workspace = true, optional = true }
16+
serde = { workspace = true, optional = true }
1717
serde_json = { workspace = true, optional = true }
1818
url.workspace = true
1919

@@ -22,6 +22,6 @@ thiserror.workspace = true
2222

2323
[features]
2424
default = ["http", "json"]
25-
http = ["dep:http-types"]
26-
json = ["dep:serde_json"]
25+
http = []
26+
json = ["dep:serde", "dep:serde_json"]
2727
amqp = []

sdk/typespec/src/error/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
//! Interfaces for working with errors.
55
66
#[cfg(feature = "http")]
7-
use http_types::StatusCode;
8-
7+
use crate::http::StatusCode;
98
use std::borrow::Cow;
109
use std::fmt::{Debug, Display};
1110

sdk/typespec/src/http/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
mod status_code;
5+
6+
pub use status_code::StatusCode;

0 commit comments

Comments
 (0)