mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 01:32:57 +01:00
httpresponse: add constructor for HttpResponseBuilder (#697)
This commit is contained in:
parent
cc7f6b5eef
commit
17ecdd63d2
@ -48,10 +48,10 @@ impl HttpResponse {
|
|||||||
self.0.as_mut()
|
self.0.as_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create http response builder with specific status.
|
/// Create a new HTTP response builder with specific status.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn build(status: StatusCode) -> HttpResponseBuilder {
|
pub fn build(status: StatusCode) -> HttpResponseBuilder {
|
||||||
HttpResponsePool::get(status)
|
HttpResponseBuilder::new(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create http response builder
|
/// Create http response builder
|
||||||
@ -346,6 +346,12 @@ pub struct HttpResponseBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HttpResponseBuilder {
|
impl HttpResponseBuilder {
|
||||||
|
/// Create a new HTTP response builder with specific status.
|
||||||
|
#[inline]
|
||||||
|
pub fn new(status: StatusCode) -> HttpResponseBuilder {
|
||||||
|
HttpResponsePool::get(status)
|
||||||
|
}
|
||||||
|
|
||||||
/// Set HTTP status code of this response.
|
/// Set HTTP status code of this response.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn status(&mut self, status: StatusCode) -> &mut Self {
|
pub fn status(&mut self, status: StatusCode) -> &mut Self {
|
||||||
@ -1177,6 +1183,14 @@ mod tests {
|
|||||||
assert_eq!((v.name(), v.value()), ("cookie3", "val300"));
|
assert_eq!((v.name(), v.value()), ("cookie3", "val300"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_builder_new() {
|
||||||
|
let resp = HttpResponseBuilder::new(StatusCode::BAD_REQUEST)
|
||||||
|
.finish();
|
||||||
|
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_basic_builder() {
|
fn test_basic_builder() {
|
||||||
let resp = HttpResponse::Ok()
|
let resp = HttpResponse::Ok()
|
||||||
|
Loading…
Reference in New Issue
Block a user