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

For custom directives, need a way to stash additional information on the context #2150

Closed
scr-oath opened this issue Aug 16, 2018 · 3 comments
Milestone

Comments

@scr-oath
Copy link

I was trying to write a common directive that would provide info about requests similar to an access log but richer. I would find it really nice if the various sub-routes that satisfy the request could add additional information to the context - I tried using a Map[RequestContext, Map[String, Any]], but of course hit the request object changing throughout Route's "flow".

To write or extend the suite of directives more generally without needing to have one massive route, it would seem that changes would be required in the RequestContext object to carry around an additional payload which can be used to customize. To make it typesafe, perhaps the key could be an instance of something that carries the desired value type - using an instance rather than string, and some type of "identityHashMap" for lookup could reduce collisions that String keys might have.

@raboof
Copy link
Member

raboof commented Aug 16, 2018

I'm not sure I understand your exact use case, but I think this might be covered by #1500: as noted there, you can currently add custom headers to a request/response to pass along extra information with the message. Does that apply? If not, could you explain your use case a bit more?

@scr-oath
Copy link
Author

Well… I was trying to design an app where several classes could provide their own routes and to have an outer directive that logged whatever it could find about the request/response. I was hoping that individual routes could add info to the context and that context could be examined by the logger to write out whatever seemed reasonable. Instead, at current PR, it needs to call one of several functions that return a Directive0 from the info that's created/extracted etc from the routes which seems harder to manage than having one directive. I'll look at #1500 and see if that gives me access to dynamic things (i.e. not just strings, but maybe a Map[String, String], e.g. that can be adjusted throughout each request)

@scr-oath
Copy link
Author

So… reading up on #1500 and giving that technique a whirl, it seems we don't NEED anything to make this work nicely. Thanks.

@jlprat jlprat added this to the duplicate milestone Aug 17, 2018
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

3 participants