Re: Set-Cookie and Cookie Optimized Binary Encoding

James M Snell <jasnell@gmail.com> Sun, 20 January 2013 00:13 UTC

Return-Path: <ietf-http-wg-request@listhub.w3.org>
X-Original-To: ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com
Delivered-To: ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 4D97C21F86FD for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Sat, 19 Jan 2013 16:13:21 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -8.682
X-Spam-Level:
X-Spam-Status: No, score=-8.682 tagged_above=-999 required=5 tests=[AWL=0.716, BAYES_00=-2.599, HTML_MESSAGE=0.001, J_CHICKENPOX_35=0.6, J_CHICKENPOX_73=0.6, RCVD_IN_DNSWL_HI=-8]
Received: from mail.ietf.org ([64.170.98.30]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CAjxFD7mQxMS for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Sat, 19 Jan 2013 16:13:20 -0800 (PST)
Received: from frink.w3.org (frink.w3.org [128.30.52.56]) by ietfa.amsl.com (Postfix) with ESMTP id C9E2021F8707 for <httpbisa-archive-bis2Juki@lists.ietf.org>; Sat, 19 Jan 2013 16:13:19 -0800 (PST)
Received: from lists by frink.w3.org with local (Exim 4.72) (envelope-from <ietf-http-wg-request@listhub.w3.org>) id 1TwiVj-00018S-Cu for ietf-http-wg-dist@listhub.w3.org; Sun, 20 Jan 2013 00:11:43 +0000
Resent-Date: Sun, 20 Jan 2013 00:11:43 +0000
Resent-Message-Id: <E1TwiVj-00018S-Cu@frink.w3.org>
Received: from lisa.w3.org ([128.30.52.41]) by frink.w3.org with esmtp (Exim 4.72) (envelope-from <jasnell@gmail.com>) id 1TwiVe-00017h-2y for ietf-http-wg@listhub.w3.org; Sun, 20 Jan 2013 00:11:38 +0000
Received: from mail-ie0-f181.google.com ([209.85.223.181]) by lisa.w3.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.72) (envelope-from <jasnell@gmail.com>) id 1TwiVc-0001sp-UO for ietf-http-wg@w3.org; Sun, 20 Jan 2013 00:11:38 +0000
Received: by mail-ie0-f181.google.com with SMTP id 16so8110796iea.12 for <ietf-http-wg@w3.org>; Sat, 19 Jan 2013 16:11:11 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=GdXKbuRrbZmVRVhFbeg1IBcxHctetQx3kCjgoDB/TrE=; b=GsUUA8AzSaEvV2OnqfA0KGutl6bERUeytw6s4PU7dKGdmwhKsjniq0z7y61meO6YFF MuwtqjIRrgAK6J5I1JtOCaJAS2U1HWf0imxXGssotfGHyOAIhBRmYCYOxLv3t9XYsc7p Pz3p5UWQ1OPLKaJmEkOX54yJtst8nesvNXhZgP4a03FRjYMVf5Bpt5Zqe9cCU66SwTyZ Du98ol590fhur5wilIIYEq1D4tLettHCXRSqA7GwWM3DjZ2ViK5J4E5FEAcvHuyxuyiG vHtuoDaazjPA0sSzBpGECxoPSmzRXsvTOb2UQFSAm7Wxn4zwh4PVEGGwTsjCh3wQ7JuD QdAA==
MIME-Version: 1.0
X-Received: by 10.50.196.227 with SMTP id ip3mr5785604igc.97.1358640670910; Sat, 19 Jan 2013 16:11:10 -0800 (PST)
Received: by 10.64.26.137 with HTTP; Sat, 19 Jan 2013 16:11:09 -0800 (PST)
Received: by 10.64.26.137 with HTTP; Sat, 19 Jan 2013 16:11:09 -0800 (PST)
In-Reply-To: <591317E9-3090-4491-8694-F1E06217D6B4@mnot.net>
References: <CABP7RbcYw4=Lv_JHRAq9HNKQZ9GthE1ZhbXGC4fPna1aD3eZeA@mail.gmail.com> <591317E9-3090-4491-8694-F1E06217D6B4@mnot.net>
Date: Sat, 19 Jan 2013 16:11:09 -0800
Message-ID: <CABP7RbfTrN0GLRDrnLWvoyE5TfE+8U=0frpD0kHVcz+dqCkA2Q@mail.gmail.com>
From: James M Snell <jasnell@gmail.com>
To: Mark Nottingham <mnot@mnot.net>
Cc: ietf-http-wg@w3.org
Content-Type: multipart/alternative; boundary="14dae934117b91297e04d3ad2ea6"
Received-SPF: pass client-ip=209.85.223.181; envelope-from=jasnell@gmail.com; helo=mail-ie0-f181.google.com
X-W3C-Hub-Spam-Status: No, score=-4.5
X-W3C-Hub-Spam-Report: AWL=-1.760, BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001
X-W3C-Scan-Sig: lisa.w3.org 1TwiVc-0001sp-UO a844f8d1b44fbbafe5be0ee8e1981502
X-Original-To: ietf-http-wg@w3.org
Subject: Re: Set-Cookie and Cookie Optimized Binary Encoding
Archived-At: <http://www.w3.org/mid/CABP7RbfTrN0GLRDrnLWvoyE5TfE+8U=0frpD0kHVcz+dqCkA2Q@mail.gmail.com>
Resent-From: ietf-http-wg@w3.org
X-Mailing-List: <ietf-http-wg@w3.org> archive/latest/16028
X-Loop: ietf-http-wg@w3.org
Resent-Sender: ietf-http-wg-request@w3.org
Precedence: list
List-Id: <ietf-http-wg.w3.org>
List-Help: <http://www.w3.org/Mail/>
List-Post: <mailto:ietf-http-wg@w3.org>
List-Unsubscribe: <mailto:ietf-http-wg-request@w3.org?subject=unsubscribe>

Yes, indeed. I'm wondering if there's a reasonable balance we can support
here... That is, provide for backwards compatibility for most but not all
1.1 features and optimize for the most commonly used bits. Restricting set
cookie syntax could be one of those compromises.
On Jan 19, 2013 3:55 PM, "Mark Nottingham" <mnot@mnot.net> wrote:

> Keep in mind that Set-Cookie is an extensible field, and we need to leave
> that gate open. Also, the BNF in rfc6265 is very loose, which is going to
> complicate things a bit...
>
>
> On 19/01/2013, at 4:49 AM, James M Snell <jasnell@gmail.com> wrote:
>
> > Just continuing on with my exploration of improvements we could possibly
> make for the binary encoding of various headers. Currently I'm looking at
> Cookie and Set-Cookie. Here's what I've come up with so far...
> >
> > Here's an random example of a simple Set-Cookie taken from the har file
> samples Mark has collected:
> >
> >   Set-Cookie: skin=noskin; path=/; domain=.amazon.com; expires=Sat,
> 03-Nov-2012 13:04:26 GMT
> >
> > Looking at this, ignoring the actual key and value for a minute, there
> is quite a bit of wasted overhead in this format (Set-Cookie2 is even
> worse, but I'll get to that in a bit). The main question is, can we do
> better and still provide an easy 1.1 <-> 2.0 transform for Cookies. I
> definitely think we can. Here's what I have in mind:
> >
> > +-----------------------------------------+
> > |H|S|B|P|M|X|X|X|len(key)|key|len(val)|val|
> > +-----------------------------------------+
> > |len(path)|path|len(domain)|domain|expires|
> > +-----------------------------------------+
> > |num_params|... repeating param key block |
> > +-----------------------------------------+
> >
> >   H = Http-Only Bit
> >   S = Secure-Only Bit
> >   B = Binary-Value Bit
> >   P = Optional-Param List Bit (indicates whether the Set-Cookie includes
> the optional parameters block (third row in the record above)
> >   M = Max-Age Bit - If set, the expires field specifies the Maximum-Age
> of the Cookie, otherwise expires is a compact encoded date time (as we've
> already discussed). Either way, the expires field is always 4 bytes.
> >   X = Reserved Flag Bit
> >
> >   len(key)    -> 1 byte
> >   len(val)    -> 4 bytes
> >   len(path)   -> 2 bytes
> >   len(domain) -> 2 bytes
> >   expires     -> 4 bytes
> >
> > For typical Set-Cookies, with no optional parameters (I'll explain this
> later) this gives us 14-bytes of overhead. For the example cookie above, we
> go from 78 bytes down to 36 bytes. In the Http/1 format, adding HttpOnly
> and Secure flags adds at least 18 bytes of additional data. In this
> optimized form those require no additional space.
> >
> > When set, the Binary Value bit indicates that the val field contains
> arbitrary binary data as opposed to encoded-text. As Mark and others have
> pointed out, allowing for Binary cookie values can lead to trouble with
> backwards compatibility with 1.1 applications. To address this I propose
> the following: When translating an optimized Http/2 Set-Cookie to Http/1,
> if the Binary Value Bit is set, the val is Base64 encoded and a new
> "Binary" flag is added to the Http/1 Set-Cookie. For example:
> >
> >   Set-Cookie: data={base64}; path=/; domain=.example.net; expires=...;
> HttpOnly; Secure; Binary
> >
> > When translating from Http/1 to Http/2, if the Set-Cookie includes the
> Binary flag, we can attempt to base64 decode the value and include it
> directly in the optimized Http/2 record syntax directly, setting the Binary
> Value Bit, and hopefully saving significant amount of space.
> >
> > For the Cookie Header itself, we would also have a binary syntax..
> >
> > +-----------------------------------+
> > |B|XXXXXXX|len(key)|key|len(val)|val|
> > +-----------------------------------+
> >
> >   B = Binary-Value Bit
> >
> > When value is simple text, this record format actually comes out longer
> than the existing format, but that's OK, I think. For binary cookie values,
> however, this format gives us the option of reducing the record size
> significantly. So it's a tradeoff. Here, however, the translation to and
> from Http/1 gets a bit more difficult because the Cookie header does not
> allow for optional flags the way Set-Cookie does, so we have to get a bit
> creative. What I propose is that we use a convention similar to that used
> in RFC5987 and append an asterisk * to the key name..
> >
> > For example, when translating a Http/2 Binary Cookie header to Http/1,
> it would be encoded as:
> >
> >   Cookie: key*={base64}
> >
> > When translating back to Http/2, if we see the * in the key name, we can
> attempt to base64 decode the value and set the Binary Value Flag in the
> Http/2 Binary Cookie header. It's not perfect, but it ought to work.
> >
> > Getting back to Set-Cookie, there's the part about the optional
> parameters. While the current Set-Cookie format is pretty stable, there
> have been times in the past (Set-Cookie2) where additional parameters were
> specified. Set-Cookie is one of those things where it may make sense to
> support some long term extensibility. For that purpose, I have included 3
> additional reserved flag bits and an optional block of extension key=value
> pairs that can be tacked on at the end. If the Optional Parameter Bit is
> set, we know to go looking for those additional parameters at the end. The
> value of those parameters must be text, keys are text. len(key) = 1 byte,
> len(val) = 4 bytes. This gives a significant amount of latitude for
> extension and translates fine to the existing Http/1 Set-Cookie syntax.
> >
> > With these changes, I estimate that we can reduce the overall overhead
> of transmitting Set-Cookie and Cookie values by around 50% on average,
> while maintaining compatibility with Http/1.
> >
> > Thoughts?
> >
>
> --
> Mark Nottingham   http://www.mnot.net/
>
>
>
>