Re: JSON headers

On Mon, Jul 11, 2016 at 11:58:03PM -0400, Yanick Rochon wrote:
> On 11 July 2016 at 23:22, Willy Tarreau <w@1wt.eu> wrote:
> 
> > On Mon, Jul 11, 2016 at 03:47:32PM -0400, Yanick Rochon wrote:
> > > On 11 July 2016 at 15:25, Willy Tarreau <w@1wt.eu> wrote:
> > >
> > For me it means it sent two values for the Accept header defined as a list,
> > the first one being "appliation/xml...", and the second one
> > "text/plain...".
> > ... *snip*
> 
> 
> > Since it seams easy to me I'm having an issue understanding the deeper
> > problem and am pretty sure I missed something :-/
> >
> 
> Well, first arrays are enclosed in square brackets, nor curly ones :)

OK thanks :-)

> Second, I am not talking about the format per se, but about possible
> headers being sent as described (i.e. with duplicated keys). Of course,
> JavaScript objects cannot have duplicate keys, however JSON representations
> as strings are not bound to this limitation, and may very well be sent as
> such. (Also, even if it is expected that every values must be an array,
> JSON allows a few more possible values to be set, like strings, etc.) The
> point is that, { "Accept": "...", "Accept": [ "..." ] } is a valid JSON
> object, yet is (or should be) invalid as header value. What then?

But precisely my point is to declare that all JSON headers are lists (or
arrays apparently in JSON). Thus you just send array *elements* and the
recipient appends them to the array. So you don't have the object above,
you just have { "Accept": [ "..." ] }. This removes the possibility of
duplicate keys and keeps the ability to have multiple values for a header.
And it also allows to stop at the first value when you expect to use only
one value for a header that you don't intend to check for uniqueness.

Willy

Received on Tuesday, 12 July 2016 04:14:20 UTC