Skip to content

Implement Deref to C for Authorization<C> #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/common/authorization.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Authorization header and types.

use std::ops::Deref;

use base64;
use bytes::Bytes;

Expand Down Expand Up @@ -56,6 +58,14 @@ impl Authorization<Bearer> {
}
}

impl<C: Credentials> Deref for Authorization<C> {
type Target = C;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl<C: Credentials> ::Header for Authorization<C> {
fn name() -> &'static ::HeaderName {
&::http::header::AUTHORIZATION
Expand Down
2 changes: 1 addition & 1 deletion src/common/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::ops::{Bound, RangeBounds};
/// # ABNF
///
/// ```text
/// Range = byte-ranges-specifier / other-ranges-specifier
/// Range = byte-ranges-specifier / other-ranges-specifier
/// other-ranges-specifier = other-range-unit "=" other-range-set
/// other-range-set = 1*VCHAR
///
Expand Down
16 changes: 7 additions & 9 deletions src/util/flat_csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@ impl<Sep: Separator> FlatCsv<Sep> {
in_quotes = false;
}
false // dont split
} else if c == Sep::CHAR {
true // split
} else {
if c == Sep::CHAR {
true // split
} else {
if c == '"' {
in_quotes = true;
}
false // dont split
if c == '"' {
in_quotes = true;
}
false // dont split
}
})
.map(|item| item.trim())
Expand Down Expand Up @@ -113,7 +111,7 @@ impl<'a, Sep: Separator> FromIterator<&'a HeaderValue> for FlatCsv<Sep> {
.next()
.cloned()
.map(|val| BytesMut::from(val.as_bytes()))
.unwrap_or_else(|| BytesMut::new());
.unwrap_or_else(BytesMut::new);

for val in values {
buf.extend_from_slice(&[Sep::BYTE, b' ']);
Expand Down Expand Up @@ -144,7 +142,7 @@ impl<Sep: Separator> FromIterator<HeaderValue> for FlatCsv<Sep> {
let mut buf = values
.next()
.map(|val| BytesMut::from(val.as_bytes()))
.unwrap_or_else(|| BytesMut::new());
.unwrap_or_else(BytesMut::new);

for val in values {
buf.extend_from_slice(&[Sep::BYTE, b' ']);
Expand Down
2 changes: 1 addition & 1 deletion src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ impl TryFromValues for HeaderValue {
where
I: Iterator<Item = &'i HeaderValue>,
{
values.next().cloned().ok_or_else(|| ::Error::invalid())
values.next().cloned().ok_or_else(::Error::invalid)
}
}