Re: Declarative HTTP Spec Test Suite

Lucas Pardue <lucas@lucaspardue.com> Wed, 29 May 2024 22:04 UTC

Return-Path: <ietf-http-wg-request+bounce-httpbisa-archive-bis2juki=ietf.org@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 A761CC14CF1E for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Wed, 29 May 2024 15:04:53 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -7.848
X-Spam-Level:
X-Spam-Status: No, score=-7.848 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, HTML_MESSAGE=0.001, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_PASS=-0.001, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=w3.org header.b="n8uqz9CM"; dkim=pass (2048-bit key) header.d=w3.org header.b="pvH/JJil"; dkim=pass (2048-bit key) header.d=lucaspardue.com header.b="bbLkKECp"; dkim=pass (2048-bit key) header.d=messagingengine.com header.b="RjLe1nO7"
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XDu4LGvBP0iF for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Wed, 29 May 2024 15:04:48 -0700 (PDT)
Received: from mab.w3.org (mab.w3.org [IPv6:2600:1f18:7d7a:2700:d091:4b25:8566:8113]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 65874C14F5FB for <httpbisa-archive-bis2Juki@ietf.org>; Wed, 29 May 2024 15:04:48 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=w3.org; s=s1; h=Subject:Content-Type:Cc:To:From:Date:References:In-Reply-To: Message-Id:MIME-Version:Reply-To; bh=Cvux0vmT1KzOEh0gbqtS+RUusp0QQ9FAIeOAel7PUQ8=; b=n8uqz9CM+Wr/HBk9r34a0robn8 JkdtsJ/GCaNmUbKqcY79os55Si0frQC7z9x87xFTHm6bQm2xeUN2drCOSNcc6w0613S3hfroRXbk3 vloQBX2qmTelCRCqbItghI/8glEROZLN6TWy8KEoVm9TO2Tepx+ACebUk77hJ3aOqlhChrebphBBE 8mO9aUuTTV+TfPtav4FyS1InXSmO0GalqaoFvVfrpOfGDYAVJDOJtDn235oYPjfFhhRWni3QIMZmW fOAWeB8iju2dX0EfkRsZ++QfUi1zdXysvcxn1PMC+TCJasWbnmrIfKorebnDA8fchbpjpaQYJlVO/ FmM93fXw==;
Received: from lists by mab.w3.org with local (Exim 4.96) (envelope-from <ietf-http-wg-request@listhub.w3.org>) id 1sCROy-001P5c-0i for ietf-http-wg-dist@listhub.w3.org; Wed, 29 May 2024 22:04:08 +0000
Resent-Date: Wed, 29 May 2024 22:04:08 +0000
Resent-Message-Id: <E1sCROy-001P5c-0i@mab.w3.org>
Received: from ip-10-0-0-144.ec2.internal ([10.0.0.144] helo=pan.w3.org) by mab.w3.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from <lucas@lucaspardue.com>) id 1sCROu-001P4c-12 for ietf-http-wg@listhub.w3.internal; Wed, 29 May 2024 22:04:04 +0000
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=w3.org; s=s1; h=Content-Type:Subject:Cc:To:From:Date:References:In-Reply-To: Message-Id:MIME-Version:Reply-To; bh=Cvux0vmT1KzOEh0gbqtS+RUusp0QQ9FAIeOAel7PUQ8=; t=1717020244; x=1717884244; b=pvH/JJilEcHGDBPOKsF1cPeEy6DkqtCVEd63Imu23DgbB+6wdJtkXdpZRmH+9+T0AlQ79Vde6KP /5xjdTBZx+DBLYOjxtLEwrQb6hoqotGhDeviSvqXC6mGabNKDLH2tDFK4jJv4j0NdmsWV+9omOLkT PcGQ3lVNfdvGcgQUrjpSw2llQp8JTdXu2c/qtPCn98hBLKUyOhfm641DT4waCq3iG5EPhX4q3rRuq gdZlS9FgDqJDoPsG+BDoRZTw37JhSh0v3T1adaOm+Z1ZZrI+hHEJHzujiV8d0G0Khs4PUlstfY8hy AUTDo98QGeTPnBlQagh62d0QWpFTFETuI0KQ==;
Received-SPF: pass (pan.w3.org: domain of lucaspardue.com designates 103.168.172.155 as permitted sender) client-ip=103.168.172.155; envelope-from=lucas@lucaspardue.com; helo=fhigh4-smtp.messagingengine.com;
Received: from fhigh4-smtp.messagingengine.com ([103.168.172.155]) by pan.w3.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from <lucas@lucaspardue.com>) id 1sCROs-009MDh-1L for ietf-http-wg@w3.org; Wed, 29 May 2024 22:04:04 +0000
Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id F2B2511400B7; Wed, 29 May 2024 18:03:58 -0400 (EDT)
Received: from imap53 ([10.202.2.103]) by compute3.internal (MEProxy); Wed, 29 May 2024 18:03:58 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lucaspardue.com; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1717020238; x= 1717106638; bh=Cvux0vmT1KzOEh0gbqtS+RUusp0QQ9FAIeOAel7PUQ8=; b=b bLkKECp4+J3i0doE66bRG5DFPcO1wuYwsxsxBlq/eltKhHWziGh/taeP8F0pe4Zv Cj1Kp8ro3G7p/nmn1qyKN/nehI2BtSqY3L5vhf5PTP9hkG6m0PqVcrwuizzXt1Ym E6ecTsuLWj043J88f1K7GW3ZVdIif7xhg9TZ2CE7lYtAnin9F/Avcoz/oLNnVzQa TaTfJSsdBgj9nuOLIb/bduXSon3izhUwsdgUhz97M8g2Fs04xevteYQOqWn5/qAR Vf1HmB9PaRlFNF0zH64YdvHv69uzw+je9N6OskKQV1r/iZBV1BHPV99kkF1kszOi 7T4p59pHNZfdkb3XqpwJQ==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1717020238; x=1717106638; bh=Cvux0vmT1KzOEh0gbqtS+RUusp0Q Q9FAIeOAel7PUQ8=; b=RjLe1nO7LW0XPCZjyvCDLqYrbFh9K0DqXjps6+9Dk5dq VsVYVBNgYlkVR2yRwjGvJNw11AiObZPf40n2Poa//7inD05aOH4NGpLKlHU1oSCv YZuf979UoANFyz2uv6mYmyJ2m7Uf+IloQL3wN2VSzT84NcB6xw2aall0jEnT8byS /mZboCiJhgbmXbLsAbhoDzyPbwWCu5iYNK3+mB0qklCi6NNHPoqED0qcI3lz1k1a qHKw6o85QVYnhER2fYkG7Xk7xvPeUi+4Kzrg9obxDtCLc8/+n8QrCa3c9WIp8E5U xQ8m5fDcEX+c32+jLdMtUvpvBJQPrhjH4ii6rLYBrA==
X-ME-Sender: <xms:TqZXZuwaupKM5UfXJEM6O4G0N2eFKk_pyV3Of9lhdRSoqF49gqiHgQ> <xme:TqZXZqSa827qooUTzhXLdef86kZTggppJqSGFmUK7qxi864Zb8dHThDlbEhIjC6RE 26ozfwZR0jQ2myAlMc>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdekvddgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsegrtderreerreejnecuhfhrohhmpedfnfhu tggrshcurfgrrhguuhgvfdcuoehluhgtrghssehluhgtrghsphgrrhguuhgvrdgtohhmqe enucggtffrrghtthgvrhhnpeegtdekfeekteeihedvteegteeiiedvgefgueekueevgeff hfejfffgtdevtdefleenucffohhmrghinhephhgrgiigrdhsvgdpghhithhhuhgsrdgtoh hmpdhrvggrughmvgdrmhgupdhhthhtphhsrdhimhdpudgsvggtrghushgvthhhrghtihhs fihhrghtuggvfhgvnhgushgrghgrihhnshhtthhruhhntggrthhiohhnrghtthgrtghksh drihhnpdhhthhtphdvrdihohhupdhhthhtphdvrdhinhdpthgvgihtphhrohhtohgtohhl shgrrhgvfihonhguvghrfhhulhdrihhnpdhivghtfhdrohhrghdprhhftgdqvgguihhtoh hrrdhorhhgpdgtrgguugihshgvrhhvvghrrdgtohhmpdhtfihithhtvghrrdgtohhmpdhh uhhrlhdruggvvhdphhhtthhpshgvrhhvvghrshhpvggtihhfihgtrghtihhonhgrnhguth hothgvshhtihhtrdhithdptggrtghhvgdqthgvshhtshdrfhihihdptggrfhhfvghinhgr thgvugifohhnuggvrhhsrdgtohhmpdhlihhnkhgvughinhdrtghomhdphhhtthhpthgvsh htihhnghhrvghsohhurhgtvghsuhhnuggvrhhthhgvghhithhhuhgsrdgtohhmnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhhutggrsheslh hutggrshhprghrughuvgdrtghomh
X-ME-Proxy: <xmx:TqZXZgWIONlD6EefAhe6bkyjRsTrOrjcNxwUmBYzmHpZmyN4uHxmkA> <xmx:TqZXZkjUxUYq1Jd8tSEyGupeVpYshTnD8F0yTEzqGlCOo3O3slDP4A> <xmx:TqZXZgDXlz3wl-9sTjF_O29nbQgx056-hUI0gU9dvFd9YlcZTyU53Q> <xmx:TqZXZlInt1kEbaDLc3jDtH87U1ej8KQdchrBygeI3a2Jipm-gBpZXQ> <xmx:TqZXZjPE5g7disYulXrrBZ85fWuS9bdGAuObna6okO8RlrwwyzfobXFc>
Feedback-ID: i23b94938:Fastmail
Received: by mailuser.nyi.internal (Postfix, from userid 501) id 992CC364006F; Wed, 29 May 2024 18:03:58 -0400 (EDT)
X-Mailer: MessagingEngine.com Webmail Interface
User-Agent: Cyrus-JMAP/3.11.0-alpha0-491-g033e30d24-fm-20240520.001-g033e30d2
MIME-Version: 1.0
Message-Id: <a21e2452-a122-4ad3-8278-e70980a6a112@app.fastmail.com>
In-Reply-To: <jVdymWwPiPmYqYprR2XiciBoG01cibifkCA_G_ph_SQN0JRw6OvLNOEvCs0GeL93bre-J2c2X3degy5JtZiWF5BrC_C5dXkszQM6wLwF1fI=@caffeinatedwonders.com>
References: <tPxvQGS7_bxKqrFish00m9LtTT_JQfE0RU1bthEcxYNTZR_uzbkEWKNOTg9c5azoZSYuDWt9pLCiS7Kd4nIWK8DPN1sOtcgbDGx4L7BeeU4=@caffeinatedwonders.com> <CAF8qwaD7j=_9JgVS8jfDMJhJeo6cYq0QT4q-QB_TJ8W7uYCokw@mail.gmail.com> <jVdymWwPiPmYqYprR2XiciBoG01cibifkCA_G_ph_SQN0JRw6OvLNOEvCs0GeL93bre-J2c2X3degy5JtZiWF5BrC_C5dXkszQM6wLwF1fI=@caffeinatedwonders.com>
Date: Wed, 29 May 2024 23:03:37 +0100
From: Lucas Pardue <lucas@lucaspardue.com>
To: Mohammed Al Sahaf <mohammed@caffeinatedwonders.com>, David Benjamin <davidben@chromium.org>
Cc: HTTP Working Group <ietf-http-wg@w3.org>
Content-Type: multipart/alternative; boundary="9a10f41c0a36444f829e9b03e22a6b59"
X-W3C-Hub-DKIM-Status: validation passed: (address=lucas@lucaspardue.com domain=lucaspardue.com), signature is good
X-W3C-Hub-DKIM-Status: validation passed: (address=lucas@lucaspardue.com domain=messagingengine.com), signature is good
X-W3C-Hub-Spam-Status: No, score=-4.1
X-W3C-Hub-Spam-Report: BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, DMARC_MISSING=0.001, HTML_MESSAGE=0.001, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, URIBL_BLOCKED=0.001, URIBL_DBL_BLOCKED_OPENDNS=0.001, W3C_AA=-1, W3C_WL=-1
X-W3C-Scan-Sig: pan.w3.org 1sCROs-009MDh-1L c9bbc48acdef03d61d8c4644fed3a418
X-Original-To: ietf-http-wg@w3.org
Subject: Re: Declarative HTTP Spec Test Suite
Archived-At: <https://www.w3.org/mid/a21e2452-a122-4ad3-8278-e70980a6a112@app.fastmail.com>
Resent-From: ietf-http-wg@w3.org
X-Mailing-List: <ietf-http-wg@w3.org> archive/latest/51980
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: <https://www.w3.org/email/>
List-Post: <mailto:ietf-http-wg@w3.org>
List-Unsubscribe: <mailto:ietf-http-wg-request@w3.org?subject=unsubscribe>

Hi Mohammed,

Thanks for bringing this topic up. It's something I care about too.

Others have already expressed some of the complications or caveats I might have mentioned. But in spite of those things, I think there is room for improvement around testing, especially through the lens of making HTTP's dark corners more accessible to the community.

There's definitely more we can do in terms of tooling and testing. I don't think there is a one size fits all approach. vtest looked good when it was presented at the HTTP Workshop in 2019 [1], good to see it still working well.

Something that's always nagged me is writing test oriented around the HTTP/2 and HTTP/3 framing layer. Especially since the H2 Rapid Rest attacks last year. Since November, I've been working on a tool to address (in Rust, since that suits my preference and our internal dev env). The tool aims to make it easier to do interactive exploration of HTTP/3 framing and stream lifecycle management, and to capture the results of that as a reproducible test sequence. It can also be controlled programmatically to write test cases, similar to vtest. We already had plans to open source this tool soon, so it's a nice coincidence to see the topic come up. An open question is if we should provide a corpus of test case examples that could emulate some of the capabilities of h2spec*. I'll post again when open sourcing happens.

Mohammed there's another HTTP workshop planned this year, so perhaps consider coming along to talk testing in person with some of the wider community.

Cheers
Lucas

* Kazu Yamamoto maintains h3spec and its great. However, it is a bit more focused on QUIC than HTTP/3. I've no doubt more test cases could be added to h3spec but for my own needs, I want a Rust-focused set of tooling.

[1] - https://daniel.haxx.se/blog/2019/04/02/the-http-workshop-2019-begins/

[2] - https://github.com/HTTPWorkshop/workshop2024/blob/main/README.md

On Wed, May 29, 2024, at 21:56, Mohammed Al Sahaf wrote:
> Good catch! I did a retest with HTTP/1 and HTTP/2 split. I excluded h2c because setting it up is a hassle for me given my convenient tools; plus it's unsupported by browsers, so perhaps only curl will have results on that. The result appears more consistent now.
> +---------+---------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------+
> |         |                                                           HTTP/1                                                          |                                      HTTP/2                                        |
> |         +-------------------------------------------------------------+-------------------------------------------------------------+------------+-----------------------------------------------------------------------+
> |         |                             HTTP                            |                            HTTPS                            | HTTP (h2c) |                                HTTPS                                  |
> +=========+=============================================================+=============================================================+============+=======================================================================+
> | curl    | `curl: (18) transfer closed with 2 bytes remaining to read` | `curl: (18) transfer closed with 2 bytes remaining to read` |     N/A    | `(92) HTTP/2 stream 1 was not closed cleanly: PROTOCOL_ERROR (err 1)` |
> |         |                                                             |                                                             |            |                                                                       |
> |         | response payload displayed                                  | response payload displayed                                  |            | response payload displayed                                            |
> +---------+-------------------------------------------------------------+-------------------------------------------------------------+------------+-----------------------------------------------------------------------+
> | Firefox | `NS_ERROR_PARTIAL_TRANSFER`                                 | `NS_ERROR_PARTIAL_TRANSFER`                                 |     N/A    | displays the full payload without reporting any errors                |
> |         |                                                             |                                                             |            |                                                                       |
> |         | response payload displayed                                  | response payload displayed                                  |            |                                                                       |
> +---------+-------------------------------------------------------------+-------------------------------------------------------------+------------+-----------------------------------------------------------------------+
> | Chrome  | `(failed)net::ERR_CONTENT_LENGTH_MISMATCH`                  | `(failed)net::ERR_CONTENT_LENGTH_MISMATCH`                  |     N/A    | displays the full payload without reporting any errors                |
> |         |                                                             |                                                             |            |                                                                       |
> |         | nothing displayed                                           | nothing displayed                                           |            |                                                                       |
> +---------+-------------------------------------------------------------+-------------------------------------------------------------+------------+-----------------------------------------------------------------------+
> 
> 
> Given the feedback on the other branches of this thread, I think it's best to scope my proposals to servers. As mentioned elsewhere, clients are harder to test. To quote Willi Tarreau:
> 
> > testing clients is very difficult because contrary to
> > servers which just have to respond to sollicitations, someone has to act
> > on the client to run the desired tests, so the approach is different
> > (and different between various clients), and I'm not convinced that a
> > same test collection would work for all implementations due to this.
> 
> All the best,
> Mohammed
> 
> 
> On Tuesday, May 28th, 2024 at 4:47 PM, David Benjamin <davidben@chromium.org> wrote:
>> The results in scenario 2 sound off. Chrome shouldn't treat ERR_CONTENT_LENGTH_MISMATCH differently between HTTP and HTTPS. I'm not familiar with their implementation, but the Firefox results similarly don't make sense. Indeed it's quite important to enforce this over HTTPS, for HTTP/1.1, because that is what defends against truncation attacks. (In principle, TLS has the close_notify alert, but close_notify is, in practice, a fiction for HTTPS. Instead we must rely on in-protocol termination signals. For HTTP/1.1, one of those signals is Content-Length.) Also it's generally on HTTPS that one can be more strict, not less, because there are fewer intermediaries to worry about.
>> 
>> Given some of your errors mention HTTP/2, I suspect you are comparing apples to oranges, and your HTTPS tests are testing HTTP/2. You mention the Go standard library, but keep in mind that Go automatically enables HTTP/2. The Content-Length header means very different things between HTTP/1.1 and HTTP/2. In HTTP/1.1, it is a critical part of framing and needs to be checked at that layer. (HTTP/1.1's framing is incredibly fragile. "Text" protocols are wonderful.) In HTTP/2, it has no impact on framing and was historically[0] considered advisory. The spec now considers it invalid, otherwise an h2-to-h1 intermediary will have problems. [1] discusses this. But that's where this mess with receivers enforcing dates to. Provided it doesn't cause you to turn around and send mis-framed HTTP/1.1, it is more-or-less safe, if sloppy, to accept it in HTTP/2.
>> 
>> David
>> 
>> [0] https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-http2-00#section-3.2.2
>> [1] https://www.rfc-editor.org/rfc/rfc9110#section-8.6-11
>> 
>> On Mon, May 27, 2024 at 7:30 AM Mohammed Al Sahaf <mohammed@caffeinatedwonders.com> wrote:
>>> Hello,
>>> 
>>> This is a proposal that is triggered by some of my involvement with the Caddy web server <https://caddyserver.com/> project. We (Caddy team) have been working towards developing a declarative test suite for the Caddy server. The discussions (particularly a comment <https://github.com/caddyserver/caddy/pull/6255#issuecomment-2088632219> by a user) led me to believe it's best to bring up the HTTP spec compliance parts with the HTTP WG for better insight and to have a common well-being check for all members of the HTTP community.
>>> 
>>> There are numerous RFCs governing HTTP and the behavior of its citizens. Compliance to the RFCs is only validated through interoperability or manual eyeing of the RFCs against the implementation. The RFCs, for good reasons, are walls of texts and are akin to legalese when it comes to interpretation. Consequently, nuanced sections are possibly missed without visible failures due to being an edge-case. Having a specification defined as a test suite in a declarative language removes much of ambiguity and enables validation of conformance by the HTTP citizens. I hope to turn this into an official proposal, but I'd like to put the draft forward for discussion to solidify the approach and the scope first.
>>> 
>>> *_Motivation_*:
>>> 
>>> Conformance is an assurance of compatibility across the various components of the web and gives confidence of breakage if any of them were to change behavior or if the HTTP semantics were to change. Conformity can also assist in optimization efforts. If the behavior is known for sure in advance, certain optimizations can be applied.
>>> 
>>> Secondly, it unifies the expectations of the community. Let's take for example the HTTP semantics of the `Content-Length` header as defined in RFC 9110 <https://www.rfc-editor.org/rfc/rfc9110.html#name-content-length>. The RFC states when servers and user-agents SHOULD, SHOULD NOT, MAY, MAY NOT, AND MUST NOT send the `Content-Length` header, but it does not specify how should either of them (server and user-agent) handle cases of mismatch between content-length header value and actual content length of the payload. I have run an unscientific poll on Twitter about the assumed ideal behavior of a client if the `Content-Length` value does not match the actual content-length of the body.
>>> 
>>> First poll <https://twitter.com/MohammedSahaf/status/1792267681032253683>: What's the ideal HTTP client (e.g. curl, browser) behavior when the server includes more bytes in response body than stated in the content-length header? e.g. "Content-Length: 2", actual body length: 3.
>>> 
>>> *Responses* (19 responses):
>>>  • Ignore header; read fully (4 votes; 21.1%)
>>> 
>>>  • Read till content-length value (6 votes; 31.6%)
>>> 
>>>  • *Abort/reject (9 votes; 47.4%)*
>>> 
>>> *Reality*:
>>> When testing this scenario, I found the following:
>>> 
>>>  • `curl` aborts the connection, reporting `"(18) transfer closed with 1 bytes remaining to read"` for *plaintext HTTP* connection, and `"(92) HTTP/2 stream 1 was not closed cleanly: PROTOCOL_ERROR (err 1)"` for *HTTPS* connections.
>>> 
>>>  • Firefox fails the transfer on *plaintext HTTP* with `"NS_ERROR_NET_PARTIAL_TRANSFER"`; but with *HTTPS* connection, it only reads and displays payload per the number of bytes stated in the header value.
>>> 
>>>  • Chrome fails the transfer on *plaintext HTTP* with `"(failed)net::ERR_CONTENT_LENGTH_MISMATCH"`; but with *HTTPS* connection, it ignores the header value and displays the full payload.
>>> 
>>> Second Poll <https://twitter.com/MohammedSahaf/status/1792267687411831063>: What's the ideal HTTP client (e.g. curl, browser) behavior when the server includes fewer bytes in response body than stated in the content-length header? e.g. "Content-Length: 5", actual body length: 3
>>> 
>>> *Responses* (18 responses):
>>>  • Ignore header; read 3 (7 votes; 38.9%)
>>> 
>>>  • Pad; with what? (0 votes; 0%)
>>>  • *Reject/abort (9 votes; 50%)*
>>> 
>>>  • Other; comment (2 votes; 11.1%, none of them elaborated)
>>> 
>>> *Reality*:
>>> When testing this scenario, I found the following:
>>>  • `curl` aborts the connection, reporting `"(18) transfer closed with 1 bytes remaining to read"` for *plaintext HTTP* connection; *for HTTPS*, it prints the payload in full preceded by the message `"(92) HTTP/2 stream 1 was not closed cleanly: PROTOCOL_ERROR (err 1)"`.
>>> 
>>>  • Firefox displays the full payload *for HTTPS* connections without reporting any errors. For *plaintext HTTP,* it displays the full payload but reports an error `"NS_ERROR_NET_PARTIAL_TRANSFER"`
>>> 
>>>  • Chrome displays the full payload *for HTTPS* connections without reporting any errors. For *plaintext HTTP,* it fails to load the content and reports the error `"(failed)net::ERR_CONTENT_LENGTH_MISMATCH"`.
>>> 
>>> Third Poll <https://twitter.com/MohammedSahaf/status/1792267692700827955>: Assuming it's possible... What's the ideal HTTP client (e.g. curl, browser) behavior when the server includes negative value in the content-length header? e.g. "Content-Length: -2"
>>> 
>>> *Responses* (21 responses):
>>>  • Ignore value (7 votes; 33.3%)
>>> 
>>>  • *Reject/abort (14 votes; 66.7%)*
>>> 
>>> *Reality*:
>>> I couldn't in effect test the scenario. I'm using Caddy for all the scenarios, and the Go standard library doesn't set the `Content-Length` header if it's set to a value of less than 0 (source <https://github.com/golang/go/blob/377646589d5fb0224014683e0d1f1db35e60c3ac/src/net/http/server.go#L1201>)
>>> 
>>> Conclusion: The variation observed in the user agents and the, albeit unscientific, poll responses show a lack of consensus on the expected behavior. Each agent (human or machine) apply their own interpretations and assumptions to the protocol. The disagreement makes the evolution of the protocol difficult because of the varying expectations.
>>> 
>>> *_Method_*:
>>> 
>>> The test suite should be defined in declarative format that can be easily composed by humans and read by machines. The declarative, programming-language-agnostic format allows developers (RFC developers and software developers) of all backgrounds to contribute without a programming-language-based gate. In my research, I have found the open-source tool `hurl <https://hurl.dev/>` to be a suitable tool for defining HTTP server specification and to test it. It defines its own DSL for the request/response patterns and may be run with `--test` flag along with `--report-{json,html,tap}` to produce test results.
>>> 
>>> The testing effort may be implemented in phases. The first phase is to author the test suite in a common, public repository. This makes it accessible for web server developers to clone it and run the test suite against their own software. The second phase is to provide an interface for automated testing and a UI to display the conformance summary of each web server submitted to the list.
>>> 
>>> *_Challenges_*:
>>> 
>>> _Agnostic Tooling_: The first challenge is to find an HTTP client that implements HTTP Semantics RFCs perfectly, otherwise its own idiosyncrasies will get in the way of the validation. One would be tempted to default to `curl`, especially that `hurl` uses `curl` under the hood. However, there is a chance `curl` may have its own set of HTTP idiosyncrasies that may affect the results of the test execution. Changes to `curl` are probably not desired unless the subject behavior is confirmed to be a defect. Involvement of `curl` is voluntary to `curl`, and the team may be looped and involved into this initiative for comments if desired.
>>> 
>>> _Suitable DSL (Domain Specific Language)_: The `hurl` DSL is decent. In my experiment for a proof-of-concept, I found it lacking a few functions or operations to be perfectly suitable, e.g. indicating optionality. `hurl` has the advantage of its DSL grammar being defined as a spec with deterministic parsing. Extensions and/or changes to `hurl` to accommodate this effort is up to the `hurl` developers.
>>> 
>>> *_Prior Art_*:
>>> 
>>> There's a wiki page title HTTP Testing Resources <https://github.com/httpwg/wiki/wiki/HTTP-Testing-Resources> under the github.com/httpwg/wiki repository. The page contains the following note:
>>>  • *Note that *there is no official conformance test suite*. These tests have not been vetted for correctness by the HTTP Working Group, and the authority for conformance is always the relevant specification.*
>>> 
>>> Indeed some of the listed projects have not been updated for a while. Worthy of note on the page is the cache-tests.fyi project, REDBot, and httplint (which REDBot uses).
>>> 
>>> The REDBot project (by Mark Nottingham) was used by one of Caddy users to report a gap <https://github.com/caddyserver/caddy/issues/5849> in the conformance, which was subsequently fixed. Using REDBot requires pointing at a particular resource.
>>> 
>>> The cache-tests.fyi is of keen interest for some inspiration of design. The test suite is close in essence to this proposal, which is a declarative suite that can be run by cache system developers to validate their conformance to the cache related RFCs. The Souin <https://github.com/darkweak/souin> caching system runs the cache-tests.fyi test suite on every pull request to note its conformance level and to watch for variations. The display of each system, the use case, and its conformance status allows the users and the developers to take appropriate actions. The website and the UI can be a phase-2 (long-term goal) of this proposal, but the details of how to set up the system and run the tests can be postponed until more information is known about the test suite itself.
>>> 
>>> *_Humble Attempt_*:
>>> 
>>> To test the idea and develop a proof-of-concept, I have managed to convert 4 tests from REDBot (procedural, Python-based) to Hurl (declarative format). The test suite contains a collection of test sets in nested directory structure. The suite declares the URL it will call for each test case so web servers can be configured accordingly for the subject URL. The GitHub repository for the PoC is here: github.com/mohammed90/http-semantics-test-suite. The repository currently does not have a license applied as it's only for display of PoC, though I am inclined to apply Apache-2 or any other open-source-compatible license once the approach is agreed and finalized.
>>> 
>>> All the best,
>>> Mohammed
>>> Blog <https://www.caffeinatedwonders.com/> | LinkedIn <https://www.linkedin.com/in/mohammedalsahaf/>
>>>