-
Notifications
You must be signed in to change notification settings - Fork 29
Fields/Headers take a list of Vec<(String, String)> to create, but probably should take Vec<(String, List<String>)> #12
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
Comments
I wondered about this as well. One reason why perhaps not is: in the underlying protocols, iiuc, the fields are just a sequence of key/value pairs and thus if we cluster them by key, we're losing the protocol order which I could hypothetically imagine affecting some applications in corner cases. Also, for at least some common HTTP libraries (1,2), list-of-string-pairs is offered as the lower-level ground truth. Also, when you want to perform a higher-level mapping of a key to 0..N values, then the method you want is But that's just my understanding based on a partial knowledge of this space, so I'm happy to hear other thoughts too. |
This is notable because quite a few services (notably Cloudflare) use the details of this header ordering & header key case ( Not something that most normal HTTP API clients need to care about much, but imo it's definitely worth having low-level |
@lukewagner my biggest feedback is that there is inconsistency between the way that you create a new headers object (string, string) and the value that is returned when you call get (vec). And then of course there's also an 'append' method. I don't feel strongly, multi-header is definitely an edge case, but we should be consistent at least. |
Sorry, I think I'm missing your point. As I'm reading it, |
I believe his argument is that |
Wouldn't that also lead to the same loss in control over ordering as if |
I took a random look at a common HTTP library (https://square.github.io/okhttp/4.x/okhttp/okhttp3/-headers/) and it looks like the way they solved this is that they have both a |
Starting with what we have proposed now:
I'm guessing you're not asking for a variation on the first one that just returns the first value (hard to imagine that one being useful), but, rather, a variation on the second that just returns the first value for a given
|
Usually, such API is a result of fixing the issue of returning only the first value, while retaining backward compatibility at the API level, i.e. it's not a proper solution for a new API. |
I think that the fundamental issue is that most people's model of HTTP headers is a hash-map. This isn't correct, but it is the general mental model. If we're going to push people towards the "list of tuples" mental model, then we need to be consistent, so I would prefer
I think the challenge with Additionally given that the common (by far) case is a single |
fwiw golang also separates On the other hand, dotnet only returns the list: So maybe it doesn't matter :) |
Seems to me that |
Ah yes, I think this was an omission in #29. I'll file a follow-up fix. |
The new-entries function takes a list of
(String, String)
but the fields-get function returns aVec(String)
Headers can have multiple values per the HTTP spec, so I think that new-entries should probably take
Vec<(String, List<String>)>
The text was updated successfully, but these errors were encountered: