fix(server): send 400 responses on parse errors before closing connection
This commit is contained in:
		| @@ -150,6 +150,26 @@ impl Http1Transaction for ServerTransaction { | ||||
|         ret | ||||
|     } | ||||
|  | ||||
|     fn on_error(err: &::Error) -> Option<MessageHead<Self::Outgoing>> { | ||||
|         let status = match err { | ||||
|             &::Error::Method | | ||||
|             &::Error::Version | | ||||
|             &::Error::Header | | ||||
|             &::Error::Uri(_) => { | ||||
|                 StatusCode::BadRequest | ||||
|             }, | ||||
|             &::Error::TooLarge => { | ||||
|                 StatusCode::RequestHeaderFieldsTooLarge | ||||
|             } | ||||
|             _ => return None, | ||||
|         }; | ||||
|  | ||||
|         debug!("sending automatic response ({}) for parse error", status); | ||||
|         let mut msg = MessageHead::default(); | ||||
|         msg.subject = status; | ||||
|         Some(msg) | ||||
|     } | ||||
|  | ||||
|     fn should_error_on_parse_eof() -> bool { | ||||
|         false | ||||
|     } | ||||
| @@ -317,6 +337,11 @@ impl Http1Transaction for ClientTransaction { | ||||
|         Ok(body) | ||||
|     } | ||||
|  | ||||
|     fn on_error(_err: &::Error) -> Option<MessageHead<Self::Outgoing>> { | ||||
|         // we can't tell the server about any errors it creates | ||||
|         None | ||||
|     } | ||||
|  | ||||
|     fn should_error_on_parse_eof() -> bool { | ||||
|         true | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user