valyala / fasthttp

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http
MIT License
21.88k stars 1.76k forks source link

Accessing some context in a `RoundTripper` #1696

Closed JonasDoe closed 9 months ago

JonasDoe commented 10 months ago

I'm trying to write some RoundTrippers which for example read correlation ids and some authorization infos from the context and write them into the outgoing Request's header. It seems like there nothing as a context.Context or a client-variant of fasthttp.RequestCtx get provided in the RoundTripper's signature (hc *HostClient, req *Request, resp *Response) (retry bool, err error) (or fasthttp.Request, respectively).

Is it possible to achieve something like that with fasthttp?

erikdubbelboer commented 10 months ago

I'm afraid that there is no such thing. But what you could try is keeping this information in a map[*fasthttp.Request]Information.

JonasDoe commented 9 months ago

I see. I imagine it's rather hard to set and delete/clean up these Information properly for Request use, though, esp. if I "just" want too provide some non-intrusive RoundTrippers. I think I'll refrain from creating those for now. Thank you for the clarification!