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

Mark Nottingham <> Wed, 14 September 2016 23:26 UTC

Return-Path: <>
Received: from localhost (localhost []) by (Postfix) with ESMTP id 582FC12B0C8 for <>; Wed, 14 Sep 2016 16:26:24 -0700 (PDT)
X-Virus-Scanned: amavisd-new at
X-Spam-Flag: NO
X-Spam-Score: -8.429
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 ([]) by localhost ( []) (amavisd-new, port 10024) with ESMTP id 1iIIW-RKJnY7 for <>; Wed, 14 Sep 2016 16:26:18 -0700 (PDT)
Received: from ( []) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by (Postfix) with ESMTPS id F1FE812B005 for <>; Wed, 14 Sep 2016 16:26:17 -0700 (PDT)
Received: from lists by with local (Exim 4.80) (envelope-from <>) id 1bkJV6-0003Sa-Mh for; Wed, 14 Sep 2016 23:21:56 +0000
Resent-Date: Wed, 14 Sep 2016 23:21:56 +0000
Resent-Message-Id: <>
Received: from ([]) by with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from <>) id 1bkJUy-0003RD-RL for; Wed, 14 Sep 2016 23:21:48 +0000
Received: from ([]) by with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from <>) id 1bkJUx-0007At-7J for; Wed, 14 Sep 2016 23:21:48 +0000
Received: from [] (unknown []) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by (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 <>
In-Reply-To: <>
Date: Thu, 15 Sep 2016 09:21:19 +1000
Cc: HTTP Working Group <>
Content-Transfer-Encoding: quoted-printable
Message-Id: <>
References: <>
To: Kazuho Oku <>
X-Mailer: Apple Mail (2.3124)
Received-SPF: pass client-ip=;;
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: 1bkJUx-0007At-7J 5467e46e19a48bb15a8558035b089901
Subject: Re: Distinguishing 0-byte request body in HTTP/2
Archived-At: <>
X-Mailing-List: <> archive/latest/32396
Precedence: list
List-Id: <>
List-Help: <>
List-Post: <>
List-Unsubscribe: <>

The rules in <> 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 <>:

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 <>:

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.


> On 15 Sep 2016, at 7:17 AM, Kazuho Oku <> 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