Refactor errors internals (#556)
h2::Error now knows whether protocol errors happened because the user sent them, because it was received from the remote peer, or because the library itself emitted an error because it detected a protocol violation. It also keeps track of whether it came from a RST_STREAM or GO_AWAY frame, and in the case of the latter, it includes the additional debug data if any. Fixes #530
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
use crate::codec::RecvError;
|
||||
use crate::error::Reason;
|
||||
use crate::frame::{Pseudo, StreamId};
|
||||
use crate::proto::Open;
|
||||
use crate::proto::{Error, Open};
|
||||
|
||||
use http::{HeaderMap, Request, Response};
|
||||
|
||||
@@ -21,7 +20,7 @@ pub(crate) trait Peer {
|
||||
pseudo: Pseudo,
|
||||
fields: HeaderMap,
|
||||
stream_id: StreamId,
|
||||
) -> Result<Self::Poll, RecvError>;
|
||||
) -> Result<Self::Poll, Error>;
|
||||
|
||||
fn is_local_init(id: StreamId) -> bool {
|
||||
assert!(!id.is_zero());
|
||||
@@ -61,7 +60,7 @@ impl Dyn {
|
||||
pseudo: Pseudo,
|
||||
fields: HeaderMap,
|
||||
stream_id: StreamId,
|
||||
) -> Result<PollMessage, RecvError> {
|
||||
) -> Result<PollMessage, Error> {
|
||||
if self.is_server() {
|
||||
crate::server::Peer::convert_poll_message(pseudo, fields, stream_id)
|
||||
.map(PollMessage::Server)
|
||||
@@ -72,12 +71,12 @@ impl Dyn {
|
||||
}
|
||||
|
||||
/// Returns true if the remote peer can initiate a stream with the given ID.
|
||||
pub fn ensure_can_open(&self, id: StreamId, mode: Open) -> Result<(), RecvError> {
|
||||
pub fn ensure_can_open(&self, id: StreamId, mode: Open) -> Result<(), Error> {
|
||||
if self.is_server() {
|
||||
// Ensure that the ID is a valid client initiated ID
|
||||
if mode.is_push_promise() || !id.is_client_initiated() {
|
||||
proto_err!(conn: "cannot open stream {:?} - not client initiated", id);
|
||||
return Err(RecvError::Connection(Reason::PROTOCOL_ERROR));
|
||||
return Err(Error::library_go_away(Reason::PROTOCOL_ERROR));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -85,7 +84,7 @@ impl Dyn {
|
||||
// Ensure that the ID is a valid server initiated ID
|
||||
if !mode.is_push_promise() || !id.is_server_initiated() {
|
||||
proto_err!(conn: "cannot open stream {:?} - not server initiated", id);
|
||||
return Err(RecvError::Connection(Reason::PROTOCOL_ERROR));
|
||||
return Err(Error::library_go_away(Reason::PROTOCOL_ERROR));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user