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

Consider adding metadata property #3

Open
0xTim opened this issue Jul 9, 2023 · 4 comments
Open

Consider adding metadata property #3

0xTim opened this issue Jul 9, 2023 · 4 comments
Labels
kind/enhancement Improvements to existing feature.

Comments

@0xTim
Copy link
Contributor

0xTim commented Jul 9, 2023

There are many use cases where you may want to store some metadata on the request or even response (for example storing a request ID or a trace ID for distributed systems). Currently there's no way to do this, without adding an additional header which may not be desirable, or a pseudo header which feels like it's working around the problem rather than solving it.

Would a dictionary property or similar be something the team would consider?

@davedelong
Copy link

davedelong commented Jul 9, 2023

Yes please! When I implemented this in my own code, I used a protocol-based approach like SwiftUI's EnvironmentKey, with an underlying dictionary for storage. That made it very nice for storing arbitrary metadata on requests (authorization providers, authentication challenge responders, retry strategies, throttling behaviors, redirection handlers, etc) in a type-safe way.

@Lukasa
Copy link

Lukasa commented Jul 10, 2023

I don’t think putting metadata on the request object here is appropriate. The request object represents a HTTP request, not a request plus arbitrary context. It seems more appropriate for that combination to be separate from the specifics of this type. If it isn’t semantically part of the type, it shouldn’t be here, IMO.

@FranzBusch
Copy link
Member

I agree with @Lukasa here. These types should be the raw representation of the specs and provide a common set of types that we can share across the various frameworks and platforms. Adding arbitrary metadata or extracting common metadata from headers should be handled at a higher level like Vapor or Hummingbird.

@guoye-zhang
Copy link
Contributor

Speaking from experience. NSURLRequest supported custom properties through NSURLProtocol, and it has caused us a few headaches over the years:

  1. Unexpected memory usage because NSURLCache kept some requests in memory and didn't realize that they each kept a large graph of objects alive.
  2. Difficulty in serialization and deserialization when sending these objects across XPC since custom properties might not be secure coding compliant and we don't know which types to allow when decoding. We ended up sanitizing these properties to just property list types during serialization.

Yes, having extra metadata is often useful, but there should be a better way to achieve this than having [AnyHashable: Any] hanging on every type.

@guoye-zhang guoye-zhang added the kind/enhancement Improvements to existing feature. label Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements to existing feature.
Projects
None yet
Development

No branches or pull requests

5 participants