Skip to content

Commit 2b920eb

Browse files
committed
cargo fmt
1 parent 3a79650 commit 2b920eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+9845
-10058
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h1 align="center">http-types</h1>
1+
<h1 align="center">http-types-rs</h1>
22
<div align="center">
33
<strong>
44
Common types for HTTP operations.
@@ -9,13 +9,13 @@
99

1010
<div align="center">
1111
<!-- Crates version -->
12-
<a href="https://crates.io/crates/http-types">
13-
<img src="https://img.shields.io/crates/v/http-types.svg?style=flat-square"
12+
<a href="https://crates.io/crates/http-types-rs">
13+
<img src="https://img.shields.io/crates/v/http-types-rs.svg?style=flat-square"
1414
alt="Crates.io version" />
1515
</a>
1616
<!-- Downloads -->
17-
<a href="https://crates.io/crates/http-types">
18-
<img src="https://img.shields.io/crates/d/http-types.svg?style=flat-square"
17+
<a href="https://crates.io/crates/http-types-rs">
18+
<img src="https://img.shields.io/crates/d/http-types-rs.svg?style=flat-square"
1919
alt="Download" />
2020
</a>
2121
<!-- docs.rs docs -->
@@ -27,23 +27,23 @@
2727

2828
<div align="center">
2929
<h3>
30-
<a href="https://docs.rs/http-types">
30+
<a href="https://docs.rs/http-types-rs">
3131
API Docs
3232
</a>
3333
<span> | </span>
34-
<a href="https://github.com/http-rs/http-types/releases">
34+
<a href="https://github.com/http-rs/http-types-rs/releases">
3535
Releases
3636
</a>
3737
<span> | </span>
38-
<a href="https://github.com/http-rs/http-types/blob/main/.github/CONTRIBUTING.md">
38+
<a href="https://github.com/http-rs/http-types-rs/blob/main/.github/CONTRIBUTING.md">
3939
Contributing
4040
</a>
4141
</h3>
4242
</div>
4343

4444
## Installation
4545
```sh
46-
$ cargo add http-types
46+
$ cargo add http-types-rs
4747
```
4848

4949
## Safety
@@ -57,9 +57,9 @@ look at some of these issues:
5757
- [Issues labeled "good first issue"][good-first-issue]
5858
- [Issues labeled "help wanted"][help-wanted]
5959

60-
[contributing]: https://github.com/http-rs/http-types/blob/main/.github/CONTRIBUTING.md
61-
[good-first-issue]: https://github.com/http-rs/http-types/labels/good%20first%20issue
62-
[help-wanted]: https://github.com/http-rs/http-types/labels/help%20wanted
60+
[contributing]: https://github.com/OneOfone/http-types-rs/blob/main/.github/CONTRIBUTING.md
61+
[good-first-issue]: https://github.com/OneOfOne/http-types-rs/labels/good%20first%20issue
62+
[help-wanted]: https://github.com/OneOfOne/http-types-rs/labels/help%20wanted
6363

6464
## License
6565

rustfmt.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
hard_tabs = true
1+
# hard_tabs = true
2+
# tab_spaces = 3
23
reorder_imports = true
34
max_width = 150

src/auth/authorization.rs

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -32,99 +32,99 @@ use crate::headers::{Header, HeaderName, HeaderValue, Headers, AUTHORIZATION};
3232
/// ```
3333
#[derive(Debug)]
3434
pub struct Authorization {
35-
scheme: AuthenticationScheme,
36-
credentials: String,
35+
scheme: AuthenticationScheme,
36+
credentials: String,
3737
}
3838

3939
impl Authorization {
40-
/// Create a new instance of `Authorization`.
41-
pub fn new(scheme: AuthenticationScheme, credentials: String) -> Self {
42-
Self { scheme, credentials }
43-
}
44-
45-
/// Create a new instance from headers.
46-
pub fn from_headers(headers: impl AsRef<Headers>) -> crate::Result<Option<Self>> {
47-
let headers = match headers.as_ref().get(AUTHORIZATION) {
48-
Some(headers) => headers,
49-
None => return Ok(None),
50-
};
51-
52-
// If we successfully parsed the header then there's always at least one
53-
// entry. We want the last entry.
54-
let value = headers.iter().last().unwrap();
55-
56-
let mut iter = value.as_str().splitn(2, ' ');
57-
let scheme = iter.next();
58-
let credential = iter.next();
59-
let (scheme, credentials) = match (scheme, credential) {
60-
(None, _) => bail!(400, "Could not find scheme"),
61-
(Some(_), None) => bail!(400, "Could not find credentials"),
62-
(Some(scheme), Some(credentials)) => (scheme.parse()?, credentials.to_owned()),
63-
};
64-
65-
Ok(Some(Self { scheme, credentials }))
66-
}
67-
68-
/// Get the authorization scheme.
69-
pub fn scheme(&self) -> AuthenticationScheme {
70-
self.scheme
71-
}
72-
73-
/// Set the authorization scheme.
74-
pub fn set_scheme(&mut self, scheme: AuthenticationScheme) {
75-
self.scheme = scheme;
76-
}
77-
78-
/// Get the authorization credentials.
79-
pub fn credentials(&self) -> &str {
80-
self.credentials.as_str()
81-
}
82-
83-
/// Set the authorization credentials.
84-
pub fn set_credentials(&mut self, credentials: String) {
85-
self.credentials = credentials;
86-
}
40+
/// Create a new instance of `Authorization`.
41+
pub fn new(scheme: AuthenticationScheme, credentials: String) -> Self {
42+
Self { scheme, credentials }
43+
}
44+
45+
/// Create a new instance from headers.
46+
pub fn from_headers(headers: impl AsRef<Headers>) -> crate::Result<Option<Self>> {
47+
let headers = match headers.as_ref().get(AUTHORIZATION) {
48+
Some(headers) => headers,
49+
None => return Ok(None),
50+
};
51+
52+
// If we successfully parsed the header then there's always at least one
53+
// entry. We want the last entry.
54+
let value = headers.iter().last().unwrap();
55+
56+
let mut iter = value.as_str().splitn(2, ' ');
57+
let scheme = iter.next();
58+
let credential = iter.next();
59+
let (scheme, credentials) = match (scheme, credential) {
60+
(None, _) => bail!(400, "Could not find scheme"),
61+
(Some(_), None) => bail!(400, "Could not find credentials"),
62+
(Some(scheme), Some(credentials)) => (scheme.parse()?, credentials.to_owned()),
63+
};
64+
65+
Ok(Some(Self { scheme, credentials }))
66+
}
67+
68+
/// Get the authorization scheme.
69+
pub fn scheme(&self) -> AuthenticationScheme {
70+
self.scheme
71+
}
72+
73+
/// Set the authorization scheme.
74+
pub fn set_scheme(&mut self, scheme: AuthenticationScheme) {
75+
self.scheme = scheme;
76+
}
77+
78+
/// Get the authorization credentials.
79+
pub fn credentials(&self) -> &str {
80+
self.credentials.as_str()
81+
}
82+
83+
/// Set the authorization credentials.
84+
pub fn set_credentials(&mut self, credentials: String) {
85+
self.credentials = credentials;
86+
}
8787
}
8888

8989
impl Header for Authorization {
90-
fn header_name(&self) -> HeaderName {
91-
AUTHORIZATION
92-
}
90+
fn header_name(&self) -> HeaderName {
91+
AUTHORIZATION
92+
}
9393

94-
fn header_value(&self) -> HeaderValue {
95-
let output = format!("{} {}", self.scheme, self.credentials);
94+
fn header_value(&self) -> HeaderValue {
95+
let output = format!("{} {}", self.scheme, self.credentials);
9696

97-
// SAFETY: the internal string is validated to be ASCII.
98-
unsafe { HeaderValue::from_bytes_unchecked(output.into()) }
99-
}
97+
// SAFETY: the internal string is validated to be ASCII.
98+
unsafe { HeaderValue::from_bytes_unchecked(output.into()) }
99+
}
100100
}
101101

102102
#[cfg(test)]
103103
mod test {
104-
use super::*;
105-
use crate::headers::Headers;
106-
107-
#[test]
108-
fn smoke() -> crate::Result<()> {
109-
let scheme = AuthenticationScheme::Basic;
110-
let credentials = "0xdeadbeef202020";
111-
let authz = Authorization::new(scheme, credentials.into());
112-
113-
let mut headers = Headers::new();
114-
authz.apply_header(&mut headers);
115-
116-
let authz = Authorization::from_headers(headers)?.unwrap();
117-
118-
assert_eq!(authz.scheme(), AuthenticationScheme::Basic);
119-
assert_eq!(authz.credentials(), credentials);
120-
Ok(())
121-
}
122-
123-
#[test]
124-
fn bad_request_on_parse_error() {
125-
let mut headers = Headers::new();
126-
headers.insert(AUTHORIZATION, "<nori ate the tag. yum.>").unwrap();
127-
let err = Authorization::from_headers(headers).unwrap_err();
128-
assert_eq!(err.status(), 400);
129-
}
104+
use super::*;
105+
use crate::headers::Headers;
106+
107+
#[test]
108+
fn smoke() -> crate::Result<()> {
109+
let scheme = AuthenticationScheme::Basic;
110+
let credentials = "0xdeadbeef202020";
111+
let authz = Authorization::new(scheme, credentials.into());
112+
113+
let mut headers = Headers::new();
114+
authz.apply_header(&mut headers);
115+
116+
let authz = Authorization::from_headers(headers)?.unwrap();
117+
118+
assert_eq!(authz.scheme(), AuthenticationScheme::Basic);
119+
assert_eq!(authz.credentials(), credentials);
120+
Ok(())
121+
}
122+
123+
#[test]
124+
fn bad_request_on_parse_error() {
125+
let mut headers = Headers::new();
126+
headers.insert(AUTHORIZATION, "<nori ate the tag. yum.>").unwrap();
127+
let err = Authorization::from_headers(headers).unwrap_err();
128+
assert_eq!(err.status(), 400);
129+
}
130130
}

0 commit comments

Comments
 (0)