mirror of
https://github.com/actix/actix-web.git
synced 2024-12-24 00:50:36 +00:00
response tests
This commit is contained in:
parent
e8936fe081
commit
f4180e78fe
1 changed files with 37 additions and 2 deletions
|
@ -172,8 +172,11 @@ impl HttpResponse {
|
||||||
|
|
||||||
/// Keep-alive status for this connection
|
/// Keep-alive status for this connection
|
||||||
pub fn keep_alive(&self) -> Option<bool> {
|
pub fn keep_alive(&self) -> Option<bool> {
|
||||||
if let Some(ConnectionType::KeepAlive) = self.connection_type {
|
if let Some(ct) = self.connection_type {
|
||||||
Some(true)
|
match ct {
|
||||||
|
ConnectionType::KeepAlive => Some(true),
|
||||||
|
ConnectionType::Close | ConnectionType::Upgrade => Some(false),
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -406,3 +409,35 @@ fn parts<'a>(parts: &'a mut Option<Parts>, err: &Option<HttpError>) -> Option<&'
|
||||||
}
|
}
|
||||||
parts.as_mut()
|
parts.as_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_body() {
|
||||||
|
assert!(Body::Length(10).has_body());
|
||||||
|
assert!(Body::Streaming.has_body());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_upgrade() {
|
||||||
|
let resp = HttpResponse::builder(StatusCode::OK)
|
||||||
|
.upgrade().body(Body::Empty).unwrap();
|
||||||
|
assert!(resp.upgrade())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_force_close() {
|
||||||
|
let resp = HttpResponse::builder(StatusCode::OK)
|
||||||
|
.force_close().body(Body::Empty).unwrap();
|
||||||
|
assert!(!resp.keep_alive().unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_content_type() {
|
||||||
|
let resp = HttpResponse::builder(StatusCode::OK)
|
||||||
|
.content_type("text/plain").body(Body::Empty).unwrap();
|
||||||
|
assert_eq!(resp.headers().get(header::CONTENT_TYPE).unwrap(), "text/plain")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue