Skip to content

Commit

Permalink
ahh
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Aug 21, 2024
1 parent 7908840 commit 8351cd4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
5 changes: 1 addition & 4 deletions crates/httpwg-loona/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,7 @@ where
// then read the full request body
let mut req_body_len = 0;
loop {
let chunk = req_body
.next_chunk()
.await
.map_err(TestDriverError::RequestBodyError)?;
let chunk = req_body.next_chunk().await?;
match chunk {
BodyChunk::Done { trailers } => {
// yey
Expand Down
10 changes: 8 additions & 2 deletions crates/loona/src/h1/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,15 @@ where
BodyError(#[from] BodyError),
}

impl<OurBodyError> AsRef<dyn std::error::Error> for WriteBodyError<OurBodyError> {
impl<OurBodyError> AsRef<dyn std::error::Error> for WriteBodyError<OurBodyError>
where
OurBodyError: AsRef<dyn std::error::Error>,
{
fn as_ref(&self) -> &(dyn std::error::Error + 'static) {
self
match self {
Self::InnerBodyError(e) => e.as_ref(),
Self::BodyError(e) => e.as_ref(),
}
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/loona/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub mod error;
pub trait ServerDriver<OurEncoder>
where
OurEncoder: Encoder,
<OurEncoder as Encoder>::Error: AsRef<dyn StdError>,
{
type Error: AsRef<dyn StdError>;

Expand Down
23 changes: 15 additions & 8 deletions crates/loona/tests/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use loona::{
net::{TcpReadHalf, TcpWriteHalf},
IntoHalves, RollMut,
},
error::BoxError,
h1, Body, BodyChunk, Encoder, ExpectResponseHeaders, HeadersExt, Responder, Response,
ResponseDone, ServerDriver,
};
Expand All @@ -17,7 +18,10 @@ pub struct ProxyDriver {
pub pool: TransportPool,
}

impl<OurEncoder> ServerDriver<OurEncoder> for ProxyDriver {
impl<OurEncoder> ServerDriver<OurEncoder> for ProxyDriver
where
OurEncoder: Encoder,
{
type Error = BoxError;

async fn handle(
Expand Down Expand Up @@ -65,18 +69,21 @@ impl<OurEncoder> ServerDriver<OurEncoder> for ProxyDriver {
}
}

struct ProxyClientDriver<E>
struct ProxyClientDriver<OurEncoder>
where
E: Encoder,
OurEncoder: Encoder,
{
respond: Responder<E, ExpectResponseHeaders>,
respond: Responder<OurEncoder, ExpectResponseHeaders>,
}

impl h1::ClientDriver for ProxyClientDriver<E> {
type Return = Responder<E, ResponseDone>;
impl<OurEncoder> h1::ClientDriver for ProxyClientDriver<OurEncoder>
where
OurEncoder: Encoder,
{
type Return = Responder<OurEncoder, ResponseDone>;
type Error = BoxError;

async fn on_informational_response(&mut self, res: Response) -> eyre::Result<()> {
async fn on_informational_response(&mut self, res: Response) -> Result<(), BoxError> {
debug!("Got informational response {}", res.status);
Ok(())
}
Expand All @@ -85,7 +92,7 @@ impl h1::ClientDriver for ProxyClientDriver<E> {
self,
res: Response,
body: &mut impl Body,
) -> eyre::Result<Self::Return> {
) -> Result<Self::Return, BoxError> {
let respond = self.respond;
let mut respond = respond.write_final_response(res).await?;

Expand Down

0 comments on commit 8351cd4

Please sign in to comment.