Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw http request in handle functions #11

Open
Satont opened this issue Feb 8, 2024 · 1 comment
Open

Raw http request in handle functions #11

Satont opened this issue Feb 8, 2024 · 1 comment

Comments

@Satont
Copy link
Contributor

Satont commented Feb 8, 2024

Might be good to get raw http request for own need, for example tracing.
Also might be good to pass ctx from request to handlers

What do you think?

@dnsge
Copy link
Owner

dnsge commented Feb 11, 2024

For your first question:

I can see the use for passing the raw HTTP request. How do you envision this feature? Like modifying every handler signature to pass the raw Request object too? e.g. HandleChannelUpdate func(req *http.Request, h *esb.ResponseHeaders, event *esb.EventChannelUpdate)

Or were you thinking adding some general handler OnRequest(req *http.Request) to the SubHandler? This second case could probably be implemented by wrapping the SubHandler as it implements http.Handler. Going with the first option of adding a function parameter to every handler would be a breaking change, and so if I were to make that I may also redesign some bits of the library that I'm unhappy with.

For your second question:

As for passing the request context (I assume you mean the context returned from r.Context()) to the handler functions, for example HandleChannelUpdate func(ctx context.Context, h *esb.ResponseHeaders, event *esb.EventChannelUpdate), I'm not sure. It feels a bit like an anti-pattern to pass the context of a request that is about to finish to an asynchronous event handler.

However, there is context.Context.WithoutCancel, which could be used to just copy the values in the context detached from the deadline associated with the request. If you just need the key-values in the context, you could probably construct an empty context at the start of the handler, populate it, and pass it on. I'm hesitant about making these handlers take a ton of arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants