Skip to content

Commit c049ccd

Browse files
committed
fix
1 parent 75a1bc3 commit c049ccd

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/rfc9421/sign.base.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe(RFC9421SignatureBaseFactory, () => {
103103
...Object.entries(requestBase.headers),
104104
...['x-test', 'value'],
105105
...['x-test', 'value2'],
106-
...['x-test', null],
106+
...['X-Test', null],
107107
].flat(2),
108108
} satisfies RequestLike;
109109
const factory = new RFC9421SignatureBaseFactory(

src/rfc9421/sign.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// TODO
33

44
import { canonicalizeHeaderValue, encodeArrayBufferToBase64, getValueByLc, lcObjectKey, getMap, correctHeaders } from "../utils";
5-
import type { IncomingRequest, MapLikeObj, OutgoingResponse, SFVParametersLike, SFVSignatureInputDictionary, SFVSignatureInputDictionaryForInput, HeadersLike, HeadersValueLike } from "../types";
5+
import type { IncomingRequest, MapLikeObj, OutgoingResponse, SFVParametersLike, SFVSignatureInputDictionary, SFVSignatureInputDictionaryForInput, HeadersLike, HeadersValueLikeArrayable } from "../types";
66
import * as sh from "structured-headers";
77
import { SFVHeaderTypeDictionary, knownSfvHeaderTypeDictionary } from "./const";
88

@@ -217,7 +217,7 @@ export class RFC9421SignatureBaseFactory<T extends IncomingRequest | OutgoingRes
217217
throw new Error(`Invalid component: ${componentIdentifier} (multiple params are specified)`);
218218
}
219219

220-
const rawValue: HeadersValueLike = (() => {
220+
const rawValue: HeadersValueLikeArrayable = (() => {
221221
if (isReq) {
222222
if (isTr) {
223223
if ('trailers' in this.request && this.request.trailers) {

src/types.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import type { IncomingMessage, ServerResponse } from "http";
22
import type { Http2ServerRequest, Http2ServerResponse } from "http2";
33
import type { webcrypto } from "node:crypto";
44

5-
export type HeadersValueLike = string | number | null | undefined | (string | number | null | undefined)[];
6-
export type HeadersLike = Record<string, HeadersValueLike>;
5+
export type HeadersValueLike = string | number | null | undefined;
6+
export type HeadersValueLikeArrayable = HeadersValueLike | HeadersValueLike[];
7+
export type HeadersLike = Record<string, HeadersValueLikeArrayable>;
78

89
export type RequestLike = {
910
url: string;
1011
method: string;
1112
headers: HeadersLike
1213
// https://nodejs.org/api/http2.html#requestrawheaders
13-
rawHeaders?: (string | number | null | undefined)[];
14+
rawHeaders?: HeadersValueLike[];
1415
getHeaders?: () => HeadersLike;
1516
body?: string;
1617
trailers?: Record<string, string>;
@@ -26,7 +27,7 @@ export type ResponseLike = {
2627
statusCode: number;
2728
headers: HeadersLike;
2829
// https://nodejs.org/api/http2.html#requestrawheaders
29-
rawHeaders?: (string | number | null | undefined)[];
30+
rawHeaders?: HeadersValueLike[];
3031
getHeaders?: () => HeadersLike;
3132
body?: string;
3233
trailers?: Record<string, string>;

src/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MapLikeObj, SignInfo, SignatureHashAlgorithmUpperSnake, HeadersLike, HeadersValueLike } from './types.js';
1+
import type { MapLikeObj, SignInfo, SignatureHashAlgorithmUpperSnake, HeadersLike, HeadersValueLike, HeadersValueLikeArrayable } from './types.js';
22
import { ParsedAlgorithmIdentifier, getNistCurveFromOid, getPublicKeyAlgorithmNameFromOid } from './pem/spki.js';
33
import type { webcrypto } from 'node:crypto';
44

@@ -17,7 +17,7 @@ export function removeObsoleteLineFolding(str: string): string {
1717
/**
1818
* RFC 9421 2.1 (If the correctly combined value is not directly available for a given field by an implementation, ...)
1919
*/
20-
export function canonicalizeHeaderValue(value: HeadersValueLike): string {
20+
export function canonicalizeHeaderValue(value: HeadersValueLikeArrayable): string {
2121
if (typeof value === 'number') return value.toString();
2222
if (!value) return '';
2323
if (typeof value === 'string') return removeObsoleteLineFolding(value).trim();
@@ -102,13 +102,13 @@ export function toStringOrToLc(src: string | number | undefined | null): string
102102
* Convert rawHeaders to object
103103
* rawHeaders: https://nodejs.org/api/http2.html#requestrawheaders
104104
*/
105-
export function correctHeaders(src: (string | number | undefined | null)[]): Record<string, (string | number)[]> {
105+
export function correctHeaders(src: HeadersValueLike[]): Record<string, (string | number)[]> {
106106
return src.reduce((dst, prop, i) => {
107107
if (i % 2 === 0) {
108108
if (typeof prop !== 'string') {
109109
throw new Error(`Invalid header key type '${typeof prop}' of ${prop}`);
110110
}
111-
if (prop in dst) return dst;
111+
if (prop.toLowerCase() in dst) return dst;
112112
dst[prop.toLowerCase()] = [];
113113
} else {
114114
dst[toStringOrToLc(src[i - 1])].push(prop == null ? '' : prop.toString());

0 commit comments

Comments
 (0)