Re: Distinguishing 0-byte request body in HTTP/2

Mark Nottingham <mnot@mnot.net> Wed, 14 September 2016 23:26 UTC

Return-Path: <ietf-http-wg-request+bounce-httpbisa-archive-bis2juki=lists.ie@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 582FC12B0C8 for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Wed, 14 Sep 2016 16:26:24 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -8.429
X-Spam-Level:
X-Spam-Status: No, score=-8.429 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.001, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.508, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1iIIW-RKJnY7 for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Wed, 14 Sep 2016 16:26:18 -0700 (PDT)
Received: from frink.w3.org (frink.w3.org [128.30.52.56]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id F1FE812B005 for <httpbisa-archive-bis2Juki@lists.ietf.org>; Wed, 14 Sep 2016 16:26:17 -0700 (PDT)
Received: from lists by frink.w3.org with local (Exim 4.80) (envelope-from <ietf-http-wg-request@listhub.w3.org>) id 1bkJV6-0003Sa-Mh for ietf-http-wg-dist@listhub.w3.org; Wed, 14 Sep 2016 23:21:56 +0000
Resent-Date: Wed, 14 Sep 2016 23:21:56 +0000
Resent-Message-Id: <E1bkJV6-0003Sa-Mh@frink.w3.org>
Received: from lisa.w3.org ([128.30.52.41]) by frink.w3.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from <mnot@mnot.net>) id 1bkJUy-0003RD-RL for ietf-http-wg@listhub.w3.org; Wed, 14 Sep 2016 23:21:48 +0000
Received: from mxout-07.mxes.net ([216.86.168.182]) by lisa.w3.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from <mnot@mnot.net>) id 1bkJUx-0007At-7J for ietf-http-wg@w3.org; Wed, 14 Sep 2016 23:21:48 +0000
Received: from [192.168.3.104] (unknown [124.189.98.244]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.mxes.net (Postfix) with ESMTPSA id E321722E256; Wed, 14 Sep 2016 19:21:22 -0400 (EDT)
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\))
From: Mark Nottingham <mnot@mnot.net>
In-Reply-To: <CANatvzzZsd1HfCWowjXc5UwmgDgUqjRs3vyyU1qtyvKkPub7Fw@mail.gmail.com>
Date: Thu, 15 Sep 2016 09:21:19 +1000
Cc: HTTP Working Group <ietf-http-wg@w3.org>
Content-Transfer-Encoding: quoted-printable
Message-Id: <EEF6459F-D45A-40B2-AEF9-8E2F1C4E1C24@mnot.net>
References: <CANatvzzZsd1HfCWowjXc5UwmgDgUqjRs3vyyU1qtyvKkPub7Fw@mail.gmail.com>
To: Kazuho Oku <kazuhooku@gmail.com>
X-Mailer: Apple Mail (2.3124)
Received-SPF: pass client-ip=216.86.168.182; envelope-from=mnot@mnot.net; helo=mxout-07.mxes.net
X-W3C-Hub-Spam-Status: No, score=-8.6
X-W3C-Hub-Spam-Report: AWL=0.966, BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, W3C_AA=-1, W3C_DB=-1, W3C_IRA=-1, W3C_IRR=-3, W3C_WL=-1
X-W3C-Scan-Sig: lisa.w3.org 1bkJUx-0007At-7J 5467e46e19a48bb15a8558035b089901
X-Original-To: ietf-http-wg@w3.org
Subject: Re: Distinguishing 0-byte request body in HTTP/2
Archived-At: <http://www.w3.org/mid/EEF6459F-D45A-40B2-AEF9-8E2F1C4E1C24@mnot.net>
Resent-From: ietf-http-wg@w3.org
X-Mailing-List: <ietf-http-wg@w3.org> archive/latest/32396
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>

The rules in <http://httpwg.org/specs/rfc7230.html#message.body.length> still apply:

 - Any response to a HEAD has no body
 - Any 1xx, 204 and 304 response has no body
 - A 2xx response to a CONNECT has no body (because it's no longer HTTP after the header fields)
 - Otherwise, the message has a body which might be 0-length.

We intentionally made the set of messages without a body unable to be extended; see <http://httpwg.org/specs/rfc7231.html#considerations.for.new.methods>:

"""
Since message parsing (Section 3.3 of [RFC7230]) needs to be independent of method semantics (aside from responses to HEAD), definitions of new methods cannot change the parsing algorithm or prohibit the presence of a message body on either the request or the response message. Definitions of new methods can specify that only a zero-length message body is allowed by requiring a Content-Length header field with a value of "0".
"""

and <http://httpwg.org/specs/rfc7231.html#considerations.for.new.status.codes>:

"""
To allow existing parsers to process the response message, new status codes cannot disallow a payload, although they can mandate a zero-length payload body.
"""

Cheers,


> On 15 Sep 2016, at 7:17 AM, Kazuho Oku <kazuhooku@gmail.com> wrote:
> 
> Hi,
> 
> Is there any way for a H2 server to distinguish between a request
> without a body and a request with 0-byte body?
> 
> In HTTP/1, the distinction has been possible by looking for a
> content-length or a transfer-encoding header. And H1 applications have
> been actually looking for the headers to see if a request is
> accompanied by a body by checking the existence of these headers.
> 
> OTOH, HTTP/2 does not seem to provide a method to distinguish between the two.
> 
> A HTTP/2 client is allowed to send a request accompanied by a body
> without using the content-length header. It is also allowed to send a
> HEADERS frame with END_STREAM flag set in case the size of the body is
> zero-byte, omitting the DATA frame.
> 
> In such case, a request with zero-byte body becomes indistinguishable
> from a request without a body.
> 
> The fact becomes an issue when we need to transcode a HTTP/2 request
> to a HTTP/1 request (e.g. when a H2 proxy transmits a request to an H1
> server running upstream), because, some applications try to see if a
> POST request is accompanied by a body by checking the existence of
> content-length or transfer-encoding header, or to assert that a GET
> request is _not_ accompanied by a body by checking the non-existence
> of the headers.
> 
> As a mitigation, it is certainly possible for a H2 proxy transcoding
> to H1 to use the method of the request to see if content-length or
> transfer-encoding header should be set in such case. But my
> understanding is that generally speaking in HTTP whether if a request
> is accompanied by a body is orthogonal to which method is being used.
> 
> Could somebody clarify what I am missing, or provide a method I should
> use to accommodate the issue?
> 
> -- 
> Kazuho Oku
> 

--
Mark Nottingham   https://www.mnot.net/