@httpland/http-content-length
v1.0.0-beta.1
Published
HTTP Content-Length header middleware for standard request and response
Downloads
2
Maintainers
Readme
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
andResponse
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