diff --git a/examples/basic.rs b/examples/basic.rs index 256a990d9..011a6a8d4 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -36,7 +36,7 @@ fn index_async(req: HttpRequest) -> Once { println!("{:?}", req); - once(Ok(HttpResponse::builder(StatusCode::OK) + once(Ok(HttpResponse::build(StatusCode::OK) .content_type("text/html") .body(format!("Hello {}!", req.match_info().get("name").unwrap())) .unwrap() @@ -48,7 +48,7 @@ fn with_param(req: HttpRequest) -> Result { println!("{:?}", req); - Ok(HttpResponse::builder(StatusCode::OK) + Ok(HttpResponse::build(StatusCode::OK) .content_type("test/plain") .body(format!("Hello {}!", req.match_info().get("name").unwrap()))?) } @@ -79,7 +79,7 @@ fn main() { println!("{:?}", req); Ok(httpcodes::HTTPFound - .builder() + .build() .header("LOCATION", "/index.html") .body(Body::Empty)?) })) diff --git a/examples/tls/src/main.rs b/examples/tls/src/main.rs index 07d83b357..0be922aa7 100644 --- a/examples/tls/src/main.rs +++ b/examples/tls/src/main.rs @@ -12,7 +12,7 @@ use actix_web::*; fn index(req: HttpRequest) -> HttpResponse { println!("{:?}", req); httpcodes::HTTPOk - .builder() + .build() .content_type("text/plain") .body("Welcome!").unwrap() } @@ -38,7 +38,7 @@ fn main() { // with path parameters .resource("/", |r| r.handler(Method::GET, |req| { Ok(httpcodes::HTTPFound - .builder() + .build() .header("LOCATION", "/index.html") .body(Body::Empty)?) }))) diff --git a/examples/websocket-chat/src/main.rs b/examples/websocket-chat/src/main.rs index fa9ceaef3..d7176f56e 100644 --- a/examples/websocket-chat/src/main.rs +++ b/examples/websocket-chat/src/main.rs @@ -212,7 +212,7 @@ fn main() { .resource("/", |r| r.handler(Method::GET, |req| { Ok(httpcodes::HTTPFound - .builder() + .build() .header("LOCATION", "/static/websocket.html") .body(Body::Empty)?) })) diff --git a/src/error.rs b/src/error.rs index 13a54608e..f1cefba50 100644 --- a/src/error.rs +++ b/src/error.rs @@ -325,7 +325,7 @@ impl ErrorResponse for WsHandshakeError { match *self { WsHandshakeError::GetMethodRequired => { HTTPMethodNotAllowed - .builder() + .build() .header(header::ALLOW, "GET") .finish() .unwrap() diff --git a/src/httpcodes.rs b/src/httpcodes.rs index 5cf6b50ed..84ebb7cd3 100644 --- a/src/httpcodes.rs +++ b/src/httpcodes.rs @@ -52,8 +52,8 @@ pub const HTTPInternalServerError: StaticResponse = pub struct StaticResponse(StatusCode); impl StaticResponse { - pub fn builder(&self) -> HttpResponseBuilder { - HttpResponse::builder(self.0) + pub fn build(&self) -> HttpResponseBuilder { + HttpResponse::build(self.0) } pub fn response(&self) -> HttpResponse { HttpResponse::new(self.0, Body::Empty) @@ -87,8 +87,8 @@ mod tests { use super::{HTTPOk, HTTPBadRequest, Body, HttpResponse}; #[test] - fn test_builder() { - let resp = HTTPOk.builder().body(Body::Empty).unwrap(); + fn test_build() { + let resp = HTTPOk.build().body(Body::Empty).unwrap(); assert_eq!(resp.status(), StatusCode::OK); } diff --git a/src/httpresponse.rs b/src/httpresponse.rs index 5adb32cbb..154240058 100644 --- a/src/httpresponse.rs +++ b/src/httpresponse.rs @@ -39,8 +39,9 @@ pub struct HttpResponse { impl HttpResponse { + /// Create http response builder with specific status. #[inline] - pub fn builder(status: StatusCode) -> HttpResponseBuilder { + pub fn build(status: StatusCode) -> HttpResponseBuilder { HttpResponseBuilder { parts: Some(Parts::new(status)), err: None, @@ -450,31 +451,31 @@ mod tests { #[test] fn test_upgrade() { - let resp = HttpResponse::builder(StatusCode::OK) + let resp = HttpResponse::build(StatusCode::OK) .upgrade().body(Body::Empty).unwrap(); assert!(resp.upgrade()) } #[test] fn test_force_close() { - let resp = HttpResponse::builder(StatusCode::OK) + let resp = HttpResponse::build(StatusCode::OK) .force_close().body(Body::Empty).unwrap(); assert!(!resp.keep_alive().unwrap()) } #[test] fn test_content_type() { - let resp = HttpResponse::builder(StatusCode::OK) + let resp = HttpResponse::build(StatusCode::OK) .content_type("text/plain").body(Body::Empty).unwrap(); assert_eq!(resp.headers().get(header::CONTENT_TYPE).unwrap(), "text/plain") } #[test] fn test_content_encoding() { - let resp = HttpResponse::builder(StatusCode::OK).finish().unwrap(); + let resp = HttpResponse::build(StatusCode::OK).finish().unwrap(); assert_eq!(*resp.content_encoding(), ContentEncoding::Auto); - let resp = HttpResponse::builder(StatusCode::OK) + let resp = HttpResponse::build(StatusCode::OK) .content_encoding(ContentEncoding::Br).finish().unwrap(); assert_eq!(*resp.content_encoding(), ContentEncoding::Br); } diff --git a/src/middlewares/logger.rs b/src/middlewares/logger.rs index 4b2d386d7..72ca5103f 100644 --- a/src/middlewares/logger.rs +++ b/src/middlewares/logger.rs @@ -301,7 +301,7 @@ mod tests { headers.insert(header::USER_AGENT, header::HeaderValue::from_static("ACTIX-WEB")); let mut req = HttpRequest::new( Method::GET, "/".to_owned(), Version::HTTP_11, headers, String::new(), Payload::empty()); - let resp = HttpResponse::builder(StatusCode::OK) + let resp = HttpResponse::build(StatusCode::OK) .header("X-Test", "ttt") .force_close().body(Body::Empty).unwrap(); @@ -332,7 +332,7 @@ mod tests { headers.insert(header::USER_AGENT, header::HeaderValue::from_static("ACTIX-WEB")); let req = HttpRequest::new( Method::GET, "/".to_owned(), Version::HTTP_11, headers, String::new(), Payload::empty()); - let resp = HttpResponse::builder(StatusCode::OK) + let resp = HttpResponse::build(StatusCode::OK) .force_close().body(Body::Empty).unwrap(); let entry_time = time::now(); @@ -350,7 +350,7 @@ mod tests { let req = HttpRequest::new( Method::GET, "/".to_owned(), Version::HTTP_11, HeaderMap::new(), "test".to_owned(), Payload::empty()); - let resp = HttpResponse::builder(StatusCode::OK) + let resp = HttpResponse::build(StatusCode::OK) .force_close().body(Body::Empty).unwrap(); let entry_time = time::now(); diff --git a/src/staticfiles.rs b/src/staticfiles.rs index d19b93a55..5d11e759d 100644 --- a/src/staticfiles.rs +++ b/src/staticfiles.rs @@ -106,7 +106,7 @@ impl StaticFiles { {}\ \n", index_of, index_of, body); Ok( - HTTPOk.builder() + HTTPOk.build() .content_type("text/html; charset=utf-8") .body(html).unwrap() ) @@ -176,7 +176,7 @@ impl RouteHandler for StaticFiles { } } } else { - let mut resp = HTTPOk.builder(); + let mut resp = HTTPOk.build(); if let Some(ext) = filename.extension() { let mime = get_mime_type(&ext.to_string_lossy()); resp.content_type(format!("{}", mime).as_str()); diff --git a/src/ws.rs b/src/ws.rs index 3d9e65058..d78cbf052 100644 --- a/src/ws.rs +++ b/src/ws.rs @@ -157,7 +157,7 @@ pub fn handshake(req: &HttpRequest) -> Result