fix route by first byte

This commit is contained in:
yggverse 2025-02-03 01:20:08 +02:00
parent 788b792167
commit a5fbca2ace
4 changed files with 15 additions and 15 deletions

View file

@ -48,27 +48,27 @@ impl Response {
match result { match result {
Ok(buffer) => match buffer.first() { Ok(buffer) => match buffer.first() {
Some(byte) => match byte { Some(byte) => match byte {
1 => match Input::from_utf8(&buffer) { 0x31 => match Input::from_utf8(&buffer) {
Ok(input) => Ok(Self::Input(input)), Ok(input) => Ok(Self::Input(input)),
Err(e) => Err(Error::Input(e)), Err(e) => Err(Error::Input(e)),
}, },
2 => match Success::from_utf8(&buffer) { 0x32 => match Success::from_utf8(&buffer) {
Ok(success) => Ok(Self::Success(success)), Ok(success) => Ok(Self::Success(success)),
Err(e) => Err(Error::Success(e)), Err(e) => Err(Error::Success(e)),
}, },
3 => match Redirect::from_utf8(&buffer) { 0x33 => match Redirect::from_utf8(&buffer) {
Ok(redirect) => Ok(Self::Redirect(redirect)), Ok(redirect) => Ok(Self::Redirect(redirect)),
Err(e) => Err(Error::Redirect(e)), Err(e) => Err(Error::Redirect(e)),
}, },
4 | 5 => match Failure::from_utf8(&buffer) { 0x34 | 0x35 => match Failure::from_utf8(&buffer) {
Ok(failure) => Ok(Self::Failure(failure)), Ok(failure) => Ok(Self::Failure(failure)),
Err(e) => Err(Error::Failure(e)), Err(e) => Err(Error::Failure(e)),
}, },
6 => match Certificate::from_utf8(&buffer) { 0x36 => match Certificate::from_utf8(&buffer) {
Ok(certificate) => Ok(Self::Certificate(certificate)), Ok(certificate) => Ok(Self::Certificate(certificate)),
Err(e) => Err(Error::Certificate(e)), Err(e) => Err(Error::Certificate(e)),
}, },
b => Err(Error::Code(*b)), _ => Err(Error::Code),
}, },
None => Err(Error::Protocol), None => Err(Error::Protocol),
}, },

View file

@ -6,7 +6,7 @@ use std::{
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
Certificate(super::certificate::Error), Certificate(super::certificate::Error),
Code(u8), Code,
Failure(super::failure::Error), Failure(super::failure::Error),
Input(super::input::Error), Input(super::input::Error),
Protocol, Protocol,
@ -22,8 +22,8 @@ impl Display for Error {
Self::Certificate(e) => { Self::Certificate(e) => {
write!(f, "Certificate error: {e}") write!(f, "Certificate error: {e}")
} }
Self::Code(e) => { Self::Code => {
write!(f, "Code group error: {e}*") write!(f, "Code group error")
} }
Self::Failure(e) => { Self::Failure(e) => {
write!(f, "Failure error: {e}") write!(f, "Failure error: {e}")

View file

@ -22,15 +22,15 @@ impl Failure {
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> { pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
match buffer.first() { match buffer.first() {
Some(byte) => match byte { Some(byte) => match byte {
4 => match Temporary::from_utf8(buffer) { 0x34 => match Temporary::from_utf8(buffer) {
Ok(input) => Ok(Self::Temporary(input)), Ok(input) => Ok(Self::Temporary(input)),
Err(e) => Err(Error::Temporary(e)), Err(e) => Err(Error::Temporary(e)),
}, },
5 => match Permanent::from_utf8(buffer) { 0x35 => match Permanent::from_utf8(buffer) {
Ok(failure) => Ok(Self::Permanent(failure)), Ok(failure) => Ok(Self::Permanent(failure)),
Err(e) => Err(Error::Permanent(e)), Err(e) => Err(Error::Permanent(e)),
}, },
b => Err(Error::Code(*b)), _ => Err(Error::Code),
}, },
None => Err(Error::Protocol), None => Err(Error::Protocol),
} }

View file

@ -2,7 +2,7 @@ use std::fmt::{Display, Formatter, Result};
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
Code(u8), Code,
Permanent(super::permanent::Error), Permanent(super::permanent::Error),
Protocol, Protocol,
Temporary(super::temporary::Error), Temporary(super::temporary::Error),
@ -11,8 +11,8 @@ pub enum Error {
impl Display for Error { impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> Result { fn fmt(&self, f: &mut Formatter) -> Result {
match self { match self {
Self::Code(e) => { Self::Code => {
write!(f, "Code group error: {e}*") write!(f, "Code group error")
} }
Self::Permanent(e) => { Self::Permanent(e) => {
write!(f, "Permanent failure group error: {e}") write!(f, "Permanent failure group error: {e}")