1/**
2 * Low-level parser for multipart header blocks.
3 *
4 * @stability unstable
5 * @since 4.0.0
6 */
7import * as internal from "./internal/headers.ts"
8
9/**
10 * The reason a multipart header block could not be parsed.
11 *
12 * @stability unstable
13 * @category errors
14 * @since 4.0.0
15 */
16export type FailureReason =
17 | "TooManyHeaders"
18 | "HeaderTooLarge"
19 | "InvalidHeaderName"
20 | "InvalidHeaderValue"
21
22/**
23 * Indicates that the parser needs more input.
24 *
25 * @stability unstable
26 * @category models
27 * @since 4.0.0
28 */
29export interface Continue {
30 readonly _tag: "Continue"
31}
32
33/**
34 * A multipart header parsing failure.
35 *
36 * @stability unstable
37 * @category errors
38 * @since 4.0.0
39 */
40export interface Failure {
41 readonly _tag: "Failure"
42 readonly reason: FailureReason
43 readonly headers: Record<string, string | Array<string>>
44}
45
46/**
47 * A successfully parsed multipart header block.
48 *
49 * @stability unstable
50 * @category models
51 * @since 4.0.0
52 */
53export interface Headers {
54 readonly _tag: "Headers"
55 readonly headers: Record<string, string | Array<string>>
56 readonly endPosition: number
57}
58
59/**
60 * The result of parsing a multipart header block.
61 *
62 * @stability unstable
63 * @category models
64 * @since 4.0.0
65 */
66export type ReturnValue = Continue | Failure | Headers
67
68/**
69 * Creates an incremental multipart header parser.
70 *
71 * @stability unstable
72 * @category constructors
73 * @since 4.0.0
74 */
75export const make: () => (chunk: Uint8Array, start: number) => ReturnValue = internal.make