mirror of https://github.com/fafhrd91/actix-web
fix qitem tests
This commit is contained in:
parent
dca157abbc
commit
f7c5f67f1a
|
@ -193,21 +193,69 @@ where
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::super::encoding::*;
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
// copy of encoding from actix-web headers
|
||||||
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
|
pub enum Encoding {
|
||||||
|
Chunked,
|
||||||
|
Brotli,
|
||||||
|
Gzip,
|
||||||
|
Deflate,
|
||||||
|
Compress,
|
||||||
|
Identity,
|
||||||
|
Trailers,
|
||||||
|
EncodingExt(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Encoding {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
use Encoding::*;
|
||||||
|
f.write_str(match *self {
|
||||||
|
Chunked => "chunked",
|
||||||
|
Brotli => "br",
|
||||||
|
Gzip => "gzip",
|
||||||
|
Deflate => "deflate",
|
||||||
|
Compress => "compress",
|
||||||
|
Identity => "identity",
|
||||||
|
Trailers => "trailers",
|
||||||
|
EncodingExt(ref s) => s.as_ref(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl str::FromStr for Encoding {
|
||||||
|
type Err = crate::error::ParseError;
|
||||||
|
fn from_str(s: &str) -> Result<Encoding, crate::error::ParseError> {
|
||||||
|
use Encoding::*;
|
||||||
|
match s {
|
||||||
|
"chunked" => Ok(Chunked),
|
||||||
|
"br" => Ok(Brotli),
|
||||||
|
"deflate" => Ok(Deflate),
|
||||||
|
"gzip" => Ok(Gzip),
|
||||||
|
"compress" => Ok(Compress),
|
||||||
|
"identity" => Ok(Identity),
|
||||||
|
"trailers" => Ok(Trailers),
|
||||||
|
_ => Ok(EncodingExt(s.to_owned())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_quality_item_fmt_q_1() {
|
fn test_quality_item_fmt_q_1() {
|
||||||
|
use Encoding::*;
|
||||||
let x = qitem(Chunked);
|
let x = qitem(Chunked);
|
||||||
assert_eq!(format!("{}", x), "chunked");
|
assert_eq!(format!("{}", x), "chunked");
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_quality_item_fmt_q_0001() {
|
fn test_quality_item_fmt_q_0001() {
|
||||||
|
use Encoding::*;
|
||||||
let x = QualityItem::new(Chunked, Quality(1));
|
let x = QualityItem::new(Chunked, Quality(1));
|
||||||
assert_eq!(format!("{}", x), "chunked; q=0.001");
|
assert_eq!(format!("{}", x), "chunked; q=0.001");
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_quality_item_fmt_q_05() {
|
fn test_quality_item_fmt_q_05() {
|
||||||
|
use Encoding::*;
|
||||||
// Custom value
|
// Custom value
|
||||||
let x = QualityItem {
|
let x = QualityItem {
|
||||||
item: EncodingExt("identity".to_owned()),
|
item: EncodingExt("identity".to_owned()),
|
||||||
|
@ -218,6 +266,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_quality_item_fmt_q_0() {
|
fn test_quality_item_fmt_q_0() {
|
||||||
|
use Encoding::*;
|
||||||
// Custom value
|
// Custom value
|
||||||
let x = QualityItem {
|
let x = QualityItem {
|
||||||
item: EncodingExt("identity".to_owned()),
|
item: EncodingExt("identity".to_owned()),
|
||||||
|
@ -228,6 +277,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_quality_item_from_str1() {
|
fn test_quality_item_from_str1() {
|
||||||
|
use Encoding::*;
|
||||||
let x: Result<QualityItem<Encoding>, _> = "chunked".parse();
|
let x: Result<QualityItem<Encoding>, _> = "chunked".parse();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
x.unwrap(),
|
x.unwrap(),
|
||||||
|
@ -237,8 +287,10 @@ mod tests {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_quality_item_from_str2() {
|
fn test_quality_item_from_str2() {
|
||||||
|
use Encoding::*;
|
||||||
let x: Result<QualityItem<Encoding>, _> = "chunked; q=1".parse();
|
let x: Result<QualityItem<Encoding>, _> = "chunked; q=1".parse();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
x.unwrap(),
|
x.unwrap(),
|
||||||
|
@ -248,8 +300,10 @@ mod tests {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_quality_item_from_str3() {
|
fn test_quality_item_from_str3() {
|
||||||
|
use Encoding::*;
|
||||||
let x: Result<QualityItem<Encoding>, _> = "gzip; q=0.5".parse();
|
let x: Result<QualityItem<Encoding>, _> = "gzip; q=0.5".parse();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
x.unwrap(),
|
x.unwrap(),
|
||||||
|
@ -259,8 +313,10 @@ mod tests {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_quality_item_from_str4() {
|
fn test_quality_item_from_str4() {
|
||||||
|
use Encoding::*;
|
||||||
let x: Result<QualityItem<Encoding>, _> = "gzip; q=0.273".parse();
|
let x: Result<QualityItem<Encoding>, _> = "gzip; q=0.273".parse();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
x.unwrap(),
|
x.unwrap(),
|
||||||
|
@ -270,16 +326,19 @@ mod tests {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_quality_item_from_str5() {
|
fn test_quality_item_from_str5() {
|
||||||
let x: Result<QualityItem<Encoding>, _> = "gzip; q=0.2739999".parse();
|
let x: Result<QualityItem<Encoding>, _> = "gzip; q=0.2739999".parse();
|
||||||
assert!(x.is_err());
|
assert!(x.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_quality_item_from_str6() {
|
fn test_quality_item_from_str6() {
|
||||||
let x: Result<QualityItem<Encoding>, _> = "gzip; q=2".parse();
|
let x: Result<QualityItem<Encoding>, _> = "gzip; q=2".parse();
|
||||||
assert!(x.is_err());
|
assert!(x.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_quality_item_ordering() {
|
fn test_quality_item_ordering() {
|
||||||
let x: QualityItem<Encoding> = "gzip; q=0.5".parse().ok().unwrap();
|
let x: QualityItem<Encoding> = "gzip; q=0.5".parse().ok().unwrap();
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::{fmt, net, thread, time};
|
||||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||||
#[cfg(feature = "cookies")]
|
#[cfg(feature = "cookies")]
|
||||||
use actix_http::cookie::Cookie;
|
use actix_http::cookie::Cookie;
|
||||||
use actix_http::http::{Method, StatusCode, Uri, Version};
|
use actix_http::http::{HeaderMap, Method, StatusCode, Uri, Version};
|
||||||
use actix_http::test::TestRequest as HttpTestRequest;
|
use actix_http::test::TestRequest as HttpTestRequest;
|
||||||
use actix_http::{ws, Extensions, HttpService, Request};
|
use actix_http::{ws, Extensions, HttpService, Request};
|
||||||
use actix_router::{Path, ResourceDef, Url};
|
use actix_router::{Path, ResourceDef, Url};
|
||||||
|
|
|
@ -2,13 +2,12 @@
|
||||||
|
|
||||||
use std::{fmt, ops};
|
use std::{fmt, ops};
|
||||||
|
|
||||||
use futures_util::future::{err, ok, Ready};
|
use actix_utils::future::{err, ok, Ready};
|
||||||
|
|
||||||
use crate::dev::Payload;
|
use crate::{
|
||||||
use crate::error::ParseError;
|
dev::Payload, error::ParseError, extract::FromRequest, http::header::Header as ParseHeader,
|
||||||
use crate::extract::FromRequest;
|
HttpRequest,
|
||||||
use crate::http::header::Header as ParseHeader;
|
};
|
||||||
use crate::HttpRequest;
|
|
||||||
|
|
||||||
/// Extract typed headers from the request.
|
/// Extract typed headers from the request.
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue