# @types/http-headers

> TypeScript definitions for http-headers

Latest version **3.0.4** (published 2024-10-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @types/http-headers
pnpm add @types/http-headers
yarn add @types/http-headers
bun add @types/http-headers
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score; popular repo; extremely popular.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.4 |
| Published | 2024-10-01 |
| First published | 2022-11-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 51432 |
| Maintainers | types |

## Links

- npm: https://www.npmjs.com/package/@types/http-headers
- Repository: https://github.com/DefinitelyTyped/DefinitelyTyped
- Homepage: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/http-headers
- npm.io page: https://npm.io/package/@types/http-headers

## Dependencies (1)

- [@types/node](https://npm.io/package/@types/node.md) *

## Recent versions

- 3.0.4 (latest) — 2024-10-01
- 3.0.3 (ts4.5) — 2023-11-07
- 3.0.0 (ts4.1) — 2022-11-01
- 3.0.2 — 2023-10-18
- 3.0.1 — 2023-09-16

## README

# Installation
> `npm install --save @types/http-headers`

# Summary
This package contains type definitions for http-headers (https://github.com/watson/http-headers).

# Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/http-headers.
## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/http-headers/index.d.ts)
````ts
/// <reference types="node" />

import { ServerResponse } from "http";

export = httpHeaders;

/**
 * Parse the start-line and headers from an HTTP request or response.
 *
 * - Auto-detects and ignores body if present
 * - Fully [RFC 2068](http://www.rfc-base.org/txt/rfc-2068.txt) compliant
 * - Support multi-line headers (lines will be joined with a space)
 * - Support repeating headers
 *
 * @param data The data to parse.
 * @param [onlyHeaders=false] If `true`, only the headers object will be returned.
 *
 * @example
 * import * as net from 'net'
 * import httpHeaders = require('http-headers')
 *
 * // create TCP server
 * net.createServer((c) => {
 *   const buffers: Buffer[] = []
 *   c.on('data', buffers.push.bind(buffers))
 *   c.on('end', () => {
 *     const data = Buffer.concat(buffers)
 *
 *     // parse incoming data as an HTTP request and extra HTTP headers
 *     console.log(httpHeaders(data))
 *   })
 * }).listen(8080)
 *
 * @example
 * // If given an instance of `http.ServerResponse`, the response headers are
 * // automatically extracted, parsed and returned:
 *
 * import * as http from 'http'
 * import httpHeaders = require('http-headers')
 *
 * http.createServer((req, res) => {
 *   res.end('Hello World')
 *   console.log(httpHeaders(res))
 * }).listen(8080)
 */
declare function httpHeaders<T extends boolean>(
    data: string | Buffer | ServerResponse,
    onlyHeaders?: T,
): T extends true ? httpHeaders.Headers : (httpHeaders.RequestData | httpHeaders.ResponseData | httpHeaders.Headers);

declare namespace httpHeaders {
    interface RequestData {
        method: string;
        url: string;
        version: HttpVersion;
        headers: Headers;
    }

    interface ResponseData {
        version: HttpVersion;
        statusCode: number;
        statusMessage: string;
        headers: Headers;
    }

    interface HttpVersion {
        major: number;
        minor: number;
    }

    type Headers = {
        "set-cookie"?: string[] | undefined;
    } & { [key in string]?: string | undefined };
}

````

### Additional Details
 * Last updated: Tue, 01 Oct 2024 22:07:40 GMT
 * Dependencies: [@types/node](https://npmjs.com/package/@types/node)

# Credits
These definitions were written by [BendingBender](https://github.com/BendingBender).

---
_Source: https://npm.io/package/@types/http-headers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
