mirror of
https://github.com/actix/actix-web.git
synced 2025-01-03 13:58:44 +00:00
consistent naming
This commit is contained in:
parent
45433f71e5
commit
0519056199
10 changed files with 25 additions and 24 deletions
|
@ -36,7 +36,7 @@ fn index_async(req: HttpRequest) -> Once<actix_web::Frame, Error>
|
|||
{
|
||||
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<HttpResponse>
|
|||
{
|
||||
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)?)
|
||||
}))
|
||||
|
|
|
@ -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)?)
|
||||
})))
|
||||
|
|
|
@ -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)?)
|
||||
}))
|
||||
|
|
|
@ -325,7 +325,7 @@ impl ErrorResponse for WsHandshakeError {
|
|||
match *self {
|
||||
WsHandshakeError::GetMethodRequired => {
|
||||
HTTPMethodNotAllowed
|
||||
.builder()
|
||||
.build()
|
||||
.header(header::ALLOW, "GET")
|
||||
.finish()
|
||||
.unwrap()
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ impl StaticFiles {
|
|||
{}\
|
||||
</ul></body>\n</html>", 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<S: 'static> RouteHandler<S> 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());
|
||||
|
|
|
@ -157,7 +157,7 @@ pub fn handshake<S>(req: &HttpRequest<S>) -> Result<HttpResponse, WsHandshakeErr
|
|||
hash_key(key.as_ref())
|
||||
};
|
||||
|
||||
Ok(HttpResponse::builder(StatusCode::SWITCHING_PROTOCOLS)
|
||||
Ok(HttpResponse::build(StatusCode::SWITCHING_PROTOCOLS)
|
||||
.connection_type(ConnectionType::Upgrade)
|
||||
.header(header::UPGRADE, "websocket")
|
||||
.header(header::TRANSFER_ENCODING, "chunked")
|
||||
|
|
|
@ -18,7 +18,7 @@ fn test_response_cookies() {
|
|||
let cookies = req.load_cookies().unwrap();
|
||||
|
||||
let resp = httpcodes::HTTPOk
|
||||
.builder()
|
||||
.build()
|
||||
.cookie(Cookie::build("name", "value")
|
||||
.domain("www.rust-lang.org")
|
||||
.path("/test")
|
||||
|
|
Loading…
Reference in a new issue