Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

httpland/http-content-length

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

HTTP Content-Length header middleware for standard request and response

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.