-
Notifications
You must be signed in to change notification settings - Fork 595
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
HTTP message attributes #1500
Comments
Agreed, we currently work around this by having synthetic headers which isn't the most hygienic way to go around it and leaks sometimes. FYI @bantonsson @jrudolph |
This would be fantastically useful. 👍 |
I was thinking it would be useful to stash values on the Ultimately I don't care if this hangs off the |
For me that sounds an awful lot like the request context of Servlets/JSP (or thread local for that part). Wouldn't it be better to use functional composition and explicit state passing for these kind of things than an arbitrary map of things in context? |
@scr-oath, the whole routing layer uses immutable data structures (aside from the streaming aspects). So, it will not be possible to mutate things in inner directive and have access to it from outer directives. What you can do already now is to add custom headers to a request or a response:
This already works now but is a bit cumbersome because you need to define custom headers (though, note, that this is how HTTP works in general. E.g. in proxied setups, the proxies also add headers to requests and may read responses to communicate with backend servers). This ticket describes that we want to introduce another structure, similar to custom headers that simplifies passing around information inside of Akka HTTP but the concept will exactly be the same as with custom headers. |
Ok I understand the thirst for immutable rather than the Von Neumann style. Then, I suppose this change/feature-request would be to add arbitrary objects to the request/response (not just strings) and not to the headers (because they're not destined for output)? That would really be great! FWIW, the custom headers approach does work, but is just cumbersome it seems… so this attr idea of arbitrary non-rendered stuff would be a nice addition. |
This approach follows the Play API (https://www.playframework.com/documentation/2.8.x/Highlights26) in that you can add attributes of any user type. Otherwise it follows the existing conventions from Akka HTTP Headers, so you can have multiple attributes of the same type. If you want to distinguish different attributes of the same type, like you could in Play with different keys, you would have to introduce a wrapper type (either holding the key or creating a separate wrapper for each key). The main downside of this approach is that it increases the memory usage of a message with one field.
This approach follows the Play API (https://www.playframework.com/documentation/2.8.x/Highlights26) in that you can add attributes of any user type. Otherwise it follows the existing conventions from Akka HTTP Headers, so you can have multiple attributes of the same type. If you want to distinguish different attributes of the same type, like you could in Play with different keys, you would have to introduce a wrapper type (either holding the key or creating a separate wrapper for each key). The main downside of this approach is that it increases the memory usage of a message with one field.
This approach follows the Play API (https://www.playframework.com/documentation/2.8.x/Highlights26) in that you can add attributes of any user type. Otherwise it follows the existing conventions from Akka HTTP Headers, so you can have multiple attributes of the same type. If you want to distinguish different attributes of the same type, like you could in Play with different keys, you would have to introduce a wrapper type (either holding the key or creating a separate wrapper for each key). The main downside of this approach is that it increases the memory usage of a message with one field.
This approach follows the Play API (https://www.playframework.com/documentation/2.8.x/Highlights26) in that you can add attributes of any user type. Otherwise it follows the existing conventions from Akka HTTP Headers, so you can have multiple attributes of the same type. If you want to distinguish different attributes of the same type, like you could in Play with different keys, you would have to introduce a wrapper type (either holding the key or creating a separate wrapper for each key). The main downside of this approach is that it increases the memory usage of a message with one field.
attributes are identified by AttributeKey instance. Explicitly naming the keys doesn't seem necessary, as they are 'internal' and never serialized. Refs #1500 Co-authored-by: Johannes Rudolph <[email protected]> Co-authored-by: Marcos Pereira <[email protected]>
It would be nice if we could attach arbitrary typed values to Akka HTTP requests and responses. This could be used for things like tracking request ids/metadata, and perhaps for other things people are currently using custom headers for.
For example:
Ideally the API should be type safe so I can only assign an
Attr[A]
to a value of typeA
, but if it were possible to write a type-safe wrapper that would probably be sufficient.My future use case for this would be allowing us to completely represent a Play request as an Akka HTTP request, attaching various Play metadata as attributes.
The text was updated successfully, but these errors were encountered: