whatwg / fetch

Fetch Standard
https://fetch.spec.whatwg.org/
Other
2.11k stars 329 forks source link

"Structured field value" isn't well defined #1672

Open jyasskin opened 1 year ago

jyasskin commented 1 year ago

https://fetch.spec.whatwg.org/#concept-header-list-set-structured-header takes a "structured field value" as an argument, but RFC8941 never defines that term. In particular, it's not clear that the argument needs to specify which of the Structured Data Types is being passed. This will often be guessable from the context, but Integers and Decimals might get mixed up in some cases, as could Strings, Tokens, and Byte Sequences.

annevk commented 1 year ago

It defines it just before the example at the end of https://httpwg.org/specs/rfc8941.html#rfc.section.2.

Perhaps Fetch should have a section though with some kind of mapping between those and Infra types.

@domenic might have some thoughts about this given his work around this in HTML.

jyasskin commented 1 year ago

Ok, there is a definition, but "Specifications ... can refer its field value as a "structured header value", "structured trailer value", or "structured field value" as necessary." doesn't give enough information to know what to pass to "set a structured field value". E.g. is the field value the ascii serialization or the parsed value? If you think hard or read the algorithm, it's clear it has to be the parsed value, with its type, but novice spec authors shouldn't have to (and don't) think hard when they want to call this.

It would help some to infer types from:

[Lists](https://httpwg.org/specs/rfc8941.html#list)
[list](https://infra.spec.whatwg.org/#list)
[Dictionaries](https://httpwg.org/specs/rfc8941.html#dictionary)
[ordered maps](https://infra.spec.whatwg.org/#ordered-map)
[Integers](https://httpwg.org/specs/rfc8941.html#integer)
[long long](https://webidl.spec.whatwg.org/#idl-long-long) (but the range is less than long long, and folks might pass other integral types)
[Decimals](https://httpwg.org/specs/rfc8941.html#decimal)
[double](https://webidl.spec.whatwg.org/#idl-double) (but the range is less than double, and floats also work)
[Strings](https://httpwg.org/specs/rfc8941.html#string)
[ASCII string](https://infra.spec.whatwg.org/#ascii-string)
[Tokens](https://httpwg.org/specs/rfc8941.html#token)
[ASCII string](https://infra.spec.whatwg.org/#ascii-string) ??
[Byte Sequences](https://httpwg.org/specs/rfc8941.html#binary)
[byte sequences](https://infra.spec.whatwg.org/#byte-sequence)
[Booleans](https://httpwg.org/specs/rfc8941.html#boolean)
[boolean](https://infra.spec.whatwg.org/#boolean)

But this leaves out Parameters entirely, and I think it would be better to just be explicit that the argument needs to be in the Structured Data Type system.

mnot commented 1 year ago

Parameters do complicate things. Also, it'd be good to distinguish between Token and String if it's going to be (re-)serialised. And don't forget we're adding Date and perhaps a separate Display String that takes non-ASCII content.

@annevk if you remember we talked about this some at the last HTTP Workshop; the data model we eventually ended up looked something like:

{
  "@type": "string",
  "@val": "foo",
  "a": 1,
  "b": 2
}

... where a and b are Parameters. @type could be optional if the datatype is natively clear (as per many of the examples above).

You could also have convenience methods for various things here, of course, but in this approach you'd have to make sure their names didn't confict with potential parameters. The other way would be to put parameters into a separate namespace; e.g.,

{
  "type": "string",
  "val": "foo",
  "params": {
    "a": 1,
    "b": 2
  }
}
annevk commented 1 year ago

Yeah, though note that this is for the "internal" API between specifications.

mnot commented 1 year ago

Ah.

mnot commented 1 year ago

Note that the revision is adding Dates and Display Strings (i.e., unicode).