@httpland/http-content-length
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-beta.1 • Public • Published

http-content-length

HTTP content-length header middleware for standard Request and Response.

What

Middleware for HTTP content-length headers.

RFC 9110, 8.6 Content-Length compliant, safely add or remove content-length header.

Middleware

For a definition of Universal HTTP middleware, see the http-middleware project.

Usage

Middleware is exported by default.

import contentLength from "https://deno.land/x/http_content_length@$VERSION/mod.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

declare const request: Request;
const handler = () => new Response("hello");

const response = await contentLength(request, handler);

assertEquals(response.headers.get("content-length"), "5");

Deep dive

Based on RFC 9110, 8.6 Content-Length, it is guaranteed that there is no content-length header in the Response.

  • If the Response status code is informational(1XX).
  • If the Response status code is no content(204).
  • If HTTP request method is CONNECT and Response status code is successful(2XX).

Otherwise, it is guaranteed that the content-length header is in the Response.

License

Copyright © 2023-present httpland.

Released under the MIT license

Package Sidebar

Install

npm i @httpland/http-content-length

Weekly Downloads

10

Version

1.0.0-beta.1

License

MIT

Unpacked Size

112 kB

Total Files

53

Last publish

Collaborators

  • miyauci