From 4525c221121a7befa79e955e8879d621434a86e4 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Mon, 1 Mar 2021 17:28:39 +0100 Subject: [PATCH] Define Content-Length parser As the body concept is refactored for #604, XMLHttpRequest will need to use this algorithm for its events. We also want to require browsers to use this algorithm instead of the one defined by HTTP as part of #1156. Tests: https://github.com/web-platform-tests/wpt/pull/10548 & https://github.com/web-platform-tests/wpt/pull/27837. --- fetch.bs | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/fetch.bs b/fetch.bs index c77dba159..f00f7853c 100644 --- a/fetch.bs +++ b/fetch.bs @@ -2807,10 +2807,44 @@ consideration for the security consequences. New exceptions can be proposed by filing an issue. +

`Content-Length` header

+ +

The `Content-Length` header is largely defined in HTTP. Its processing model is +defined here as the model defined in HTTP is not compatible with web content. [[HTTP]] + +

To extract a length +from a header list headers, run these steps: + +

    +
  1. Let values be the result of + getting, decoding, and splitting `Content-Length` from + headers. + +

  2. If values is null, then return null. + +

  3. Let candidateValue be null. + +

  4. +

    For each value of values: + +

      +
    1. If candidateValue is null, then set candidateValue to + value. + +

    2. Otherwise, if value is not candidateValue, then return failure. +

    + +
  5. If candidateValue is the empty string or has a code point that is + not an ASCII digit, then return null. + +

  6. Return candidateValue, interpreted as decimal number. +

+ +

`Content-Type` header

The `Content-Type` header is largely defined in HTTP. Its processing model is -defined here as the ABNF defined in HTTP is not compatible with web content. [[HTTP]] +defined here as the model defined in HTTP is not compatible with web content. [[HTTP]]

To extract a MIME type