-
Notifications
You must be signed in to change notification settings - Fork 18k
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
proposal: net/http: add support for the upcoming "Structured Field Values for HTTP" RFC #41046
Comments
Change https://golang.org/cl/250837 mentions this issue: |
I think this is probably best outside the standard library until the RFC is accepted. Once it's in the standard library it's pretty frozen and we can't change APIs or break behavior easily. |
For sure! |
@dunglas, your README has a broken link. Should be https://pkg.go.dev/github.com/dunglas/httpsfv. |
Also, given your comment above (For sure!) it sounds like you are saying to close this proposal until at least the RFC is accepted? |
@rsc thanks, link fixed. We should at least wait for the Internet-Draft to become a RFC before merging the patch related to this proposal. However, it should happen soon. The specification is in last stages of standardization. The algorithms described in the I-D and implemented in the patch will most likely not change anymore. The proposal can probably be kept open, and we can use the time window before the publication as a RFC to review and improve the patch. |
@dunglas, I looked at at httpsfv and my first thought is: can we make this simpler? It seems like a huge amount of new API surface for HTTP. |
@rsc we can maybe reduce the API surface a bit, but probably not much. The spec defines many data structures, and several of them cannot be implemented using only Go's builtins: https://httpwg.org/http-extensions/draft-ietf-httpbis-header-structure.html#types The main difference is that SFV's maps ( Another option would be to use However I may have missed opportunities to reduce the API surface. I'm open to any suggestion to simplify this. |
It would be nice to see how widely this is adopted. Being an RFC is one thing; being widely used is another. /cc @neild |
It seems like we should put this on hold for now. We are probably going to have to rethink a bit for HTTP/3, and since there are not many uses of structured field values yet, it might make sense to wait until that work is going on too, to try to deal with potential API changes all at the same time. For now, we've already seen that nothing prevents using a third-party package for this functionality. |
Structured Field Values are now officially an RFC: https://www.rfc-editor.org/rfc/rfc8941.html Should we consider adding this implementation in |
@dunglas I looked at https://github.com/dunglas/httpsfv and I must say that I agree with @rsc that the API is large and not very Go idiomatic. My proposal would be (for standard library):
For example, I made a simpler implementation now (others: feel free to request to make it a stand-alone package if anyone else finds it useful as well) which just takes a So my API proposal would be:
So my proposal to support parameters is that one value maps to two Go fields in a struct (when there is a struct), one for the value and one for params. If target is not a struct, params are dropped (e.g., when using We should probably also look at JSON v2 design doc by @dsnet and see if we can pick some ideas there for the API. For example, the signature of Two more points:
Thank you for starting this work and bringing it at all to the Go ecosystem! |
FYI, my implementation is here: https://github.com/shogo82148/go-sfv |
@shogo82148: Also it does not look very idiomatic? Why |
RFC 9421 (HTTP Message Signatures) recently was recently moved to the standards track, and relies on RFC 8941. I understand that RFC 8941 is not widely adopted yet, but would strongly prefer to build on either an |
The current iteration is RFC 9651, which obsoletes RFC 8941. RFC 9651 is currently only referenced by drafts https://datatracker.ietf.org/doc/rfc9651/referencedby/ though it is backwards compatible with RFC 8941, which is referenced by several proposed standards https://datatracker.ietf.org/doc/rfc8941/referencedby/ plus RFC 9110 / STD 97 and RFC 9205 / BCP 56 |
I'll plan to update my implementation soon. This should be easy, there are few changes. |
Version 1.1 of my implementation now fully implements RFC 9651. |
RFC 9651 defines a common language for specifying the syntax of HTTP header values (and other parsable texts). For example, it permits defining a header as "the value of the Foo header is a List of Integers (RFC 9651)", which removes the need to describe the integer format, the list separator, and so forth. As a concrete example, RFC 9211 defines a particular entity as:
...thereby saying that the value may be "?0" or "?1" to indicate a false or true value. RFC 9651 may be used for trivial field definitions (e.g., a string) or complicated ones (e.g., a list of (integer, string) tuples where each entry may also have an associated set of key-value pairs). I don't think there is any need at this time for us to add a package for working with RFC 9651 structured values to either the standard library or an x/ repo. This is something which can be supported by third-party packages, as https://github.com/dunglas/httpsfv and demonstrate https://github.com/shogo82148/go-sfv demonstrate. There is no clearly correct API for an SFV package. github.com/dunglas/httpsfv and github.com/shogo82148/go-sfv have substantially different APIs. #41046 (comment) proposes an entirely different approach using reflection and struct tags. RFC 9651 permits defining complex nested data types, so a comprehensive implementation will not be small. Adding a implementation at this time runs a high risk of us regretting the API in the future. Many users of structured field values will not require any API at all. strconv.ParseInt suffices to parse an Integer SFV field, for example. One justification for adding a package to the standard library is to enable interoperability. (For example, a key justification for #53435 was that it enabled interoperability between third-party multierrror implementations.) I don't believe that applies here: A package which parses an HTTP header with one SFV implementation can coexist happily with a package that parses a different header with a different SFV implementation. In summary, I think this is something that's best left to third-party packages for now. |
Structured Field Values for HTTP is an upcoming RFC from the HTTP Wording Group defining a set of well-defined data types to use in HTTP headers and trailers.
This new format will improve the interoperability and the safety of HTTP by allowing to create generic parsers and serializers suitable for all HTTP headers. It is already used in the wild, for instance for the new security headers supported by Google Chrome (
Sec-Fetch-Dest
etc), theSignature
proposal in Prefer-Push or in Vulcain.After the RFC publication, it would be nice to be able to parse and generate such headers directly using the standard library.
I proposed a patch adding support for this spec in #41045. The code is also available as a standalone library: https://github.com/dunglas/httpsfv
The text was updated successfully, but these errors were encountered: