cloudflare / cloudflare/pingora

How to get additional input when call new_ctx?

Open
#316 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
27.4k
Forks
1.7k
Avg merge
6h 22m
Merged PRs (30d)
3

Description

## What is the problem your feature solves, or the need it fulfills?

We use pingora as library, pingora don't listen, just handle stream from another acceptor.

```rs
Service::handle_event(pingora_stream, self.inner.clone(), self.close_recv.clone())
.instrument(pingora_span)
.await;
```

In `fn new_ctx` we need some input from stream to create our `Self::CTX`
```rs
use pingora::{
proxy::{Session as PingoraSession}
};
struct MyCtx {
foo: String,
}
fn new_ctx(&self) -> Self::CTX {
// How I can get info from handle_event?
let s = MyCtx{
foo: ??
};
Self::CTX { sess: s }
}
async fn upstream_peer(
&self,
session: &mut PingoraSession,
ctx: &mut Self::CTX,
) -> pingora::Result>
{
ctx.foo;
}
```

## Describe the solution you'd like
when call new_ctx, add stream as input which come from `Service::handle_event`, so we can access data in

```rs
// MyPingoraStream impl IO trait
struct MyPingoraStream {
foo: String,
}
fn new_ctx(&self, stream: &dyn Any) -> Self::CTX {
let pingora_stream = stream.downcast_ref().unwrap();
let s = MyCtx{
foo: pingora_stream.foo
};
Self::CTX { sess: s }
}
```

## Describe alternatives you've considered

`Service::handle_event` add another `struct foo` as input, foo as input when call new_ctx

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.