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

HTTPServerRequest needs some custom storage #1529

Closed
schveiguy opened this Issue Jul 7, 2016 · 3 comments

Comments

Projects
None yet
4 participants
@schveiguy
Contributor

schveiguy commented Jul 7, 2016

Currently, there is the params member, which can store custom strings to be passed through the chain of processors.

However, there are plenty of use cases where I want to store something other than a string in the request data. For instance, I want to store the user id in the session, and early on in the routing, I want to fetch all the information about the user from the database, and store that User object in the request, for further access.

I don't want to cache the user data in the session, since it may change in the DB. And I don't want to fetch that data from the database at every step in the router chain.

What I'm going to do for now, is to use the params member, with the value "string" being 0 length and pointing at some object that I really know what it is. And just add casts everywhere.

This should work, but god is it ugly! HTTPServerRequest desperately needs some mechanism to store custom types according to an id or string. I understand from searching the forums that this is a recognized problem, and the backwards compatibility requires that we don't muck with how params works. I propose to add a new variable that is a Variant[string], or even void*[string], called context or something like this (hell, even if we have a void * context member), so that I can simply pass data around.

@bheads

This comment has been minimized.

Show comment
Hide comment
@bheads

bheads Jul 25, 2016

Java has attributes as part of the ServletRequest Spec:

https://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/ServletRequest.html#setAttribute(java.lang.String, java.lang.Object)

This would be a very useful addition!

bheads commented Jul 25, 2016

Java has attributes as part of the ServletRequest Spec:

https://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/ServletRequest.html#setAttribute(java.lang.String, java.lang.Object)

This would be a very useful addition!

@thaven

This comment has been minimized.

Show comment
Hide comment
@thaven

thaven Aug 14, 2016

Contributor

The Variant[string] (or a Variant typed DictionaryList) is probably the most useful. void* would be bad, because it can store only one value, so multiple libraries using it would cause trouble for sure!

Contributor

thaven commented Aug 14, 2016

The Variant[string] (or a Variant typed DictionaryList) is probably the most useful. void* would be bad, because it can store only one value, so multiple libraries using it would cause trouble for sure!

thaven added a commit to thaven/vibe.d that referenced this issue Aug 16, 2016

Added context field to HTTPServerRequest
The context field allows application specific data to be passed down the chain of request processors.
Solves vibe-d/vibe.d#1529
@s-ludwig

This comment has been minimized.

Show comment
Hide comment
@s-ludwig

s-ludwig Jul 5, 2017

Member

Fixed by 9d0a75b.

Member

s-ludwig commented Jul 5, 2017

Fixed by 9d0a75b.

@s-ludwig s-ludwig closed this Jul 5, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment