From c1af5089b92ade8df4b105e5e34ec18576a7417a Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Thu, 11 Feb 2021 22:58:35 +0000 Subject: [PATCH] add 431 and 451 status codes --- actix-http/src/h1/codec.rs | 2 +- actix-http/src/h1/decoder.rs | 2 +- actix-http/src/h1/dispatcher.rs | 36 +++++++++---------- actix-http/src/header/common/if_range.rs | 2 +- actix-http/src/header/mod.rs | 2 +- actix-http/src/http_codes.rs | 8 +++++ .../src/{httpmessage.rs => http_message.rs} | 0 actix-http/src/lib.rs | 6 ++-- actix-http/src/request.rs | 2 +- actix-http/src/response.rs | 3 +- 10 files changed, 35 insertions(+), 28 deletions(-) rename actix-http/src/{httpmessage.rs => http_message.rs} (100%) diff --git a/actix-http/src/h1/codec.rs b/actix-http/src/h1/codec.rs index d5035df2..4aeb9f12 100644 --- a/actix-http/src/h1/codec.rs +++ b/actix-http/src/h1/codec.rs @@ -199,7 +199,7 @@ mod tests { use http::Method; use super::*; - use crate::httpmessage::HttpMessage; + use crate::HttpMessage; #[test] fn test_http_request_chunked_payload_and_next_message() { diff --git a/actix-http/src/h1/decoder.rs b/actix-http/src/h1/decoder.rs index 122a815d..07461692 100644 --- a/actix-http/src/h1/decoder.rs +++ b/actix-http/src/h1/decoder.rs @@ -652,7 +652,7 @@ mod tests { use super::*; use crate::error::ParseError; use crate::http::header::{HeaderName, SET_COOKIE}; - use crate::httpmessage::HttpMessage; + use crate::HttpMessage; impl PayloadType { fn unwrap(self) -> PayloadDecoder { diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index 8d451fda..7ee2ee25 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -382,8 +382,8 @@ where } // send service call error as response - Poll::Ready(Err(e)) => { - let res: Response = e.into().into(); + Poll::Ready(Err(err)) => { + let res: Response = err.into().into(); let (res, body) = res.replace_body(()); self.as_mut().send_response(res, body.into_body())?; } @@ -421,8 +421,8 @@ where continue 'res; } - Poll::Ready(Some(Err(e))) => { - return Err(DispatchError::Service(e)) + Poll::Ready(Some(Err(err))) => { + return Err(DispatchError::Service(err)) } Poll::Pending => return Ok(PollResponse::DoNothing), @@ -443,8 +443,8 @@ where this.state.set(State::ServiceCall(fut)); } // send expect error as response - Poll::Ready(Err(e)) => { - let res: Response = e.into().into(); + Poll::Ready(Err(err)) => { + let res: Response = err.into().into(); let (res, body) = res.replace_body(()); self.as_mut().send_response(res, body.into_body())?; } @@ -492,9 +492,9 @@ where // future is error. send response and return a result. On success // to notify the dispatcher a new state is set and the outer loop // should be continue. - Poll::Ready(Err(e)) => { - let e = e.into(); - let res: Response = e.into(); + Poll::Ready(Err(err)) => { + let err = err.into(); + let res: Response = err.into(); let (res, body) = res.replace_body(()); return self.send_response(res, body.into_body()); } @@ -512,9 +512,9 @@ where } // see the comment on ExpectCall state branch's Pending. Poll::Pending => Ok(()), - // see the comment on ExpectCall state branch's Ready(Err(e)). - Poll::Ready(Err(e)) => { - let res: Response = e.into().into(); + // see the comment on ExpectCall state branch's Ready(Err(err)). + Poll::Ready(Err(err)) => { + let res: Response = err.into().into(); let (res, body) = res.replace_body(()); self.send_response(res, body.into_body()) } @@ -606,25 +606,25 @@ where // decode is partial and buffer is not full yet. // break and wait for more read. Ok(None) => break, - Err(ParseError::Io(e)) => { + Err(ParseError::Io(err)) => { self.as_mut().client_disconnected(); this = self.as_mut().project(); - *this.error = Some(DispatchError::Io(e)); + *this.error = Some(DispatchError::Io(err)); break; } Err(ParseError::TooLarge) => { if let Some(mut payload) = this.payload.take() { payload.set_error(PayloadError::Overflow); } - // Requests overflow buffer size should be responded with 413 + // Requests overflow buffer size should be responded with 431 this.messages.push_back(DispatcherMessage::Error( - Response::PayloadTooLarge().finish().drop_body(), + Response::RequestHeaderFieldsTooLarge().finish().drop_body(), )); this.flags.insert(Flags::READ_DISCONNECT); *this.error = Some(ParseError::TooLarge.into()); break; } - Err(e) => { + Err(err) => { if let Some(mut payload) = this.payload.take() { payload.set_error(PayloadError::EncodingCorrupted); } @@ -634,7 +634,7 @@ where Response::BadRequest().finish().drop_body(), )); this.flags.insert(Flags::READ_DISCONNECT); - *this.error = Some(e.into()); + *this.error = Some(err.into()); break; } } diff --git a/actix-http/src/header/common/if_range.rs b/actix-http/src/header/common/if_range.rs index 1513b7a4..0a574950 100644 --- a/actix-http/src/header/common/if_range.rs +++ b/actix-http/src/header/common/if_range.rs @@ -5,7 +5,7 @@ use crate::header::{ self, from_one_raw_str, EntityTag, Header, HeaderName, HeaderValue, HttpDate, IntoHeaderValue, InvalidHeaderValue, Writer, }; -use crate::httpmessage::HttpMessage; +use crate::HttpMessage; /// `If-Range` header, defined in [RFC7233](http://tools.ietf.org/html/rfc7233#section-3.2) /// diff --git a/actix-http/src/header/mod.rs b/actix-http/src/header/mod.rs index 9543d43b..1100a959 100644 --- a/actix-http/src/header/mod.rs +++ b/actix-http/src/header/mod.rs @@ -9,7 +9,7 @@ use percent_encoding::{AsciiSet, CONTROLS}; pub use http::header::*; use crate::error::ParseError; -use crate::httpmessage::HttpMessage; +use crate::HttpMessage; mod as_name; mod into_pair; diff --git a/actix-http/src/http_codes.rs b/actix-http/src/http_codes.rs index f421d8e2..688a08be 100644 --- a/actix-http/src/http_codes.rs +++ b/actix-http/src/http_codes.rs @@ -67,6 +67,14 @@ impl Response { static_resp!(ExpectationFailed, StatusCode::EXPECTATION_FAILED); static_resp!(UnprocessableEntity, StatusCode::UNPROCESSABLE_ENTITY); static_resp!(TooManyRequests, StatusCode::TOO_MANY_REQUESTS); + static_resp!( + RequestHeaderFieldsTooLarge, + StatusCode::REQUEST_HEADER_FIELDS_TOO_LARGE + ); + static_resp!( + UnavailableForLegalReasons, + StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS + ); static_resp!(InternalServerError, StatusCode::INTERNAL_SERVER_ERROR); static_resp!(NotImplemented, StatusCode::NOT_IMPLEMENTED); diff --git a/actix-http/src/httpmessage.rs b/actix-http/src/http_message.rs similarity index 100% rename from actix-http/src/httpmessage.rs rename to actix-http/src/http_message.rs diff --git a/actix-http/src/lib.rs b/actix-http/src/lib.rs index 15866a3d..a55aaadb 100644 --- a/actix-http/src/lib.rs +++ b/actix-http/src/lib.rs @@ -1,6 +1,6 @@ //! HTTP primitives for the Actix ecosystem. -#![deny(rust_2018_idioms)] +#![deny(rust_2018_idioms, nonstandard_style)] #![allow( clippy::type_complexity, clippy::too_many_arguments, @@ -26,7 +26,7 @@ mod extensions; mod header; mod helpers; mod http_codes; -mod httpmessage; +mod http_message; mod message; mod payload; mod request; @@ -45,7 +45,7 @@ pub use self::builder::HttpServiceBuilder; pub use self::config::{KeepAlive, ServiceConfig}; pub use self::error::{Error, ResponseError, Result}; pub use self::extensions::Extensions; -pub use self::httpmessage::HttpMessage; +pub use self::http_message::HttpMessage; pub use self::message::{Message, RequestHead, RequestHeadType, ResponseHead}; pub use self::payload::{Payload, PayloadStream}; pub use self::request::Request; diff --git a/actix-http/src/request.rs b/actix-http/src/request.rs index 1ac2f33d..18c6c888 100644 --- a/actix-http/src/request.rs +++ b/actix-http/src/request.rs @@ -9,7 +9,7 @@ use http::{header, Method, Uri, Version}; use crate::extensions::Extensions; use crate::header::HeaderMap; -use crate::httpmessage::HttpMessage; +use crate::HttpMessage; use crate::message::{Message, RequestHead}; use crate::payload::{Payload, PayloadStream}; diff --git a/actix-http/src/response.rs b/actix-http/src/response.rs index 16d4a03d..763243a6 100644 --- a/actix-http/src/response.rs +++ b/actix-http/src/response.rs @@ -867,6 +867,7 @@ mod tests { use super::*; use crate::body::Body; use crate::http::header::{HeaderValue, CONTENT_TYPE, COOKIE, SET_COOKIE}; + use crate::HttpMessage; #[test] fn test_debug() { @@ -880,8 +881,6 @@ mod tests { #[test] fn test_response_cookies() { - use crate::httpmessage::HttpMessage; - let req = crate::test::TestRequest::default() .append_header((COOKIE, "cookie1=value1")) .append_header((COOKIE, "cookie2=value2"))