1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 00:21:08 +01:00

add 431 and 451 status codes

This commit is contained in:
Rob Ede 2021-02-11 22:58:35 +00:00
parent 77efc09362
commit c1af5089b9
No known key found for this signature in database
GPG Key ID: C2A3B36E841A91E6
10 changed files with 35 additions and 28 deletions

View File

@ -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() {

View File

@ -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 {

View File

@ -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;
}
}

View File

@ -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)
///

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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};

View File

@ -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"))