mirror of
https://github.com/fafhrd91/actix-web
synced 2025-08-30 08:38:16 +02:00
Do not set default headers for websocket request
This commit is contained in:
@@ -545,101 +545,91 @@ impl fmt::Debug for ClientRequest {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{test, Client};
|
||||
use crate::Client;
|
||||
|
||||
#[test]
|
||||
fn test_debug() {
|
||||
test::run_on(|| {
|
||||
let request = Client::new().get("/").header("x-test", "111");
|
||||
let repr = format!("{:?}", request);
|
||||
assert!(repr.contains("ClientRequest"));
|
||||
assert!(repr.contains("x-test"));
|
||||
})
|
||||
let request = Client::new().get("/").header("x-test", "111");
|
||||
let repr = format!("{:?}", request);
|
||||
assert!(repr.contains("ClientRequest"));
|
||||
assert!(repr.contains("x-test"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_client_header() {
|
||||
test::run_on(|| {
|
||||
let req = Client::build()
|
||||
.header(header::CONTENT_TYPE, "111")
|
||||
.finish()
|
||||
.get("/");
|
||||
let req = Client::build()
|
||||
.header(header::CONTENT_TYPE, "111")
|
||||
.finish()
|
||||
.get("/");
|
||||
|
||||
assert_eq!(
|
||||
req.head
|
||||
.headers
|
||||
.get(header::CONTENT_TYPE)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"111"
|
||||
);
|
||||
})
|
||||
assert_eq!(
|
||||
req.head
|
||||
.headers
|
||||
.get(header::CONTENT_TYPE)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"111"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_client_header_override() {
|
||||
test::run_on(|| {
|
||||
let req = Client::build()
|
||||
.header(header::CONTENT_TYPE, "111")
|
||||
.finish()
|
||||
.get("/")
|
||||
.set_header(header::CONTENT_TYPE, "222");
|
||||
let req = Client::build()
|
||||
.header(header::CONTENT_TYPE, "111")
|
||||
.finish()
|
||||
.get("/")
|
||||
.set_header(header::CONTENT_TYPE, "222");
|
||||
|
||||
assert_eq!(
|
||||
req.head
|
||||
.headers
|
||||
.get(header::CONTENT_TYPE)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"222"
|
||||
);
|
||||
})
|
||||
assert_eq!(
|
||||
req.head
|
||||
.headers
|
||||
.get(header::CONTENT_TYPE)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"222"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn client_basic_auth() {
|
||||
test::run_on(|| {
|
||||
let req = Client::new()
|
||||
.get("/")
|
||||
.basic_auth("username", Some("password"));
|
||||
assert_eq!(
|
||||
req.head
|
||||
.headers
|
||||
.get(header::AUTHORIZATION)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"Basic dXNlcm5hbWU6cGFzc3dvcmQ="
|
||||
);
|
||||
let req = Client::new()
|
||||
.get("/")
|
||||
.basic_auth("username", Some("password"));
|
||||
assert_eq!(
|
||||
req.head
|
||||
.headers
|
||||
.get(header::AUTHORIZATION)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"Basic dXNlcm5hbWU6cGFzc3dvcmQ="
|
||||
);
|
||||
|
||||
let req = Client::new().get("/").basic_auth("username", None);
|
||||
assert_eq!(
|
||||
req.head
|
||||
.headers
|
||||
.get(header::AUTHORIZATION)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"Basic dXNlcm5hbWU="
|
||||
);
|
||||
});
|
||||
let req = Client::new().get("/").basic_auth("username", None);
|
||||
assert_eq!(
|
||||
req.head
|
||||
.headers
|
||||
.get(header::AUTHORIZATION)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"Basic dXNlcm5hbWU="
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn client_bearer_auth() {
|
||||
test::run_on(|| {
|
||||
let req = Client::new().get("/").bearer_auth("someS3cr3tAutht0k3n");
|
||||
assert_eq!(
|
||||
req.head
|
||||
.headers
|
||||
.get(header::AUTHORIZATION)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"Bearer someS3cr3tAutht0k3n"
|
||||
);
|
||||
})
|
||||
let req = Client::new().get("/").bearer_auth("someS3cr3tAutht0k3n");
|
||||
assert_eq!(
|
||||
req.head
|
||||
.headers
|
||||
.get(header::AUTHORIZATION)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"Bearer someS3cr3tAutht0k3n"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user