mirror of
https://github.com/actix/actix-extras.git
synced 2025-08-31 11:26:59 +02:00
Check code with rustfmt not to introduce format commits (#88)
This commit is contained in:
@@ -29,9 +29,7 @@ impl fmt::Display for ParseError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let display = match self {
|
||||
ParseError::Invalid => "Invalid header value".to_string(),
|
||||
ParseError::MissingScheme => {
|
||||
"Missing authorization scheme".to_string()
|
||||
}
|
||||
ParseError::MissingScheme => "Missing authorization scheme".to_string(),
|
||||
ParseError::MissingField(_) => "Missing header field".to_string(),
|
||||
ParseError::ToStrError(e) => e.to_string(),
|
||||
ParseError::Base64DecodeError(e) => e.to_string(),
|
||||
|
@@ -81,8 +81,7 @@ impl<S: Scheme> Header for Authorization<S> {
|
||||
}
|
||||
|
||||
fn parse<T: HttpMessage>(msg: &T) -> Result<Self, ParseError> {
|
||||
let header =
|
||||
msg.headers().get(AUTHORIZATION).ok_or(ParseError::Header)?;
|
||||
let header = msg.headers().get(AUTHORIZATION).ok_or(ParseError::Header)?;
|
||||
let scheme = S::parse(header).map_err(|_| ParseError::Header)?;
|
||||
|
||||
Ok(Authorization(scheme))
|
||||
|
@@ -2,9 +2,7 @@ use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
use std::str;
|
||||
|
||||
use actix_web::http::header::{
|
||||
HeaderValue, IntoHeaderValue, InvalidHeaderValue,
|
||||
};
|
||||
use actix_web::http::header::{HeaderValue, IntoHeaderValue, InvalidHeaderValue};
|
||||
use bytes::{BufMut, BytesMut};
|
||||
|
||||
use crate::headers::authorization::errors::ParseError;
|
||||
@@ -80,10 +78,7 @@ impl Scheme for Basic {
|
||||
}
|
||||
})?;
|
||||
|
||||
Ok(Basic {
|
||||
user_id,
|
||||
password,
|
||||
})
|
||||
Ok(Basic { user_id, password })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,8 +128,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_parse_header() {
|
||||
let value =
|
||||
HeaderValue::from_static("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
||||
let value = HeaderValue::from_static("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
|
||||
let scheme = Basic::parse(&value);
|
||||
|
||||
assert!(scheme.is_ok());
|
||||
|
@@ -1,9 +1,7 @@
|
||||
use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
|
||||
use actix_web::http::header::{
|
||||
HeaderValue, IntoHeaderValue, InvalidHeaderValue,
|
||||
};
|
||||
use actix_web::http::header::{HeaderValue, IntoHeaderValue, InvalidHeaderValue};
|
||||
use bytes::{BufMut, BytesMut};
|
||||
|
||||
use crate::headers::authorization::errors::ParseError;
|
||||
|
@@ -9,9 +9,7 @@ use crate::headers::authorization::errors::ParseError;
|
||||
|
||||
/// Authentication scheme for [`Authorization`](./struct.Authorization.html)
|
||||
/// header.
|
||||
pub trait Scheme:
|
||||
IntoHeaderValue + Debug + Display + Clone + Send + Sync
|
||||
{
|
||||
pub trait Scheme: IntoHeaderValue + Debug + Display + Clone + Send + Sync {
|
||||
/// Try to parse the authentication scheme from the `Authorization` header.
|
||||
fn parse(header: &HeaderValue) -> Result<Self, ParseError>;
|
||||
}
|
||||
|
@@ -5,9 +5,7 @@ use std::default::Default;
|
||||
use std::fmt;
|
||||
use std::str;
|
||||
|
||||
use actix_web::http::header::{
|
||||
HeaderValue, IntoHeaderValue, InvalidHeaderValue,
|
||||
};
|
||||
use actix_web::http::header::{HeaderValue, IntoHeaderValue, InvalidHeaderValue};
|
||||
use bytes::{BufMut, Bytes, BytesMut};
|
||||
|
||||
use super::Challenge;
|
||||
@@ -120,9 +118,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_plain_into_header_value() {
|
||||
let challenge = Basic {
|
||||
realm: None,
|
||||
};
|
||||
let challenge = Basic { realm: None };
|
||||
|
||||
let value = challenge.try_into();
|
||||
assert!(value.is_ok());
|
||||
|
@@ -2,9 +2,7 @@ use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
use std::str;
|
||||
|
||||
use actix_web::http::header::{
|
||||
HeaderValue, IntoHeaderValue, InvalidHeaderValue,
|
||||
};
|
||||
use actix_web::http::header::{HeaderValue, IntoHeaderValue, InvalidHeaderValue};
|
||||
use bytes::{BufMut, Bytes, BytesMut};
|
||||
|
||||
use super::super::Challenge;
|
||||
|
@@ -4,9 +4,7 @@ use super::*;
|
||||
fn to_bytes() {
|
||||
let b = Bearer::build()
|
||||
.error(Error::InvalidToken)
|
||||
.error_description(
|
||||
"Subject 8740827c-2e0a-447b-9716-d73042e4039d not found",
|
||||
)
|
||||
.error_description("Subject 8740827c-2e0a-447b-9716-d73042e4039d not found")
|
||||
.finish();
|
||||
|
||||
assert_eq!(
|
||||
|
@@ -7,9 +7,7 @@ pub mod basic;
|
||||
pub mod bearer;
|
||||
|
||||
/// Authentication challenge for `WWW-Authenticate` header.
|
||||
pub trait Challenge:
|
||||
IntoHeaderValue + Debug + Display + Clone + Send + Sync
|
||||
{
|
||||
pub trait Challenge: IntoHeaderValue + Debug + Display + Clone + Send + Sync {
|
||||
/// Converts the challenge into a bytes suitable for HTTP transmission.
|
||||
fn to_bytes(&self) -> Bytes;
|
||||
}
|
||||
|
Reference in New Issue
Block a user