🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

node-mocks-http

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-mocks-http - npm Package Compare versions

Comparing version

to
1.17.0

lib/headers.js

31

lib/http-mock.d.ts

@@ -22,2 +22,3 @@ import { Request, Response, CookieOptions } from 'express';

export interface Headers {
// Standard HTTP headers
accept?: string;

@@ -77,5 +78,31 @@ 'accept-language'?: string;

'www-authenticate'?: string;
// Support for arbitrary headers
[header: string]: string | string[] | undefined;
}
/**
* HeaderWebAPI interface combines the existing Headers type with
* standard Web API Headers interface methods for better compatibility
* with browser environments.
*/
export interface HeaderWebAPI {
// Include all the header properties
[header: string]: any; // 'any' to accommodate both header values and methods
// Web API Headers methods
append(name: string, value: string): void;
delete(name: string): void;
get(name: string): string | null;
has(name: string): boolean;
set(name: string, value: string): void;
forEach(callbackfn: (value: string, key: string, parent: HeaderWebAPI) => void, thisArg?: any): void;
// Iterator methods
entries(): IterableIterator<[string, string]>;
keys(): IterableIterator<string>;
values(): IterableIterator<string>;
[Symbol.iterator](): IterableIterator<[string, string]>;
}
export interface Query {

@@ -126,2 +153,4 @@ [key: string]: any;

headers: HeaderWebAPI;
// Support custom properties appended on Request objects.

@@ -145,3 +174,3 @@ [key: string]: any;

_isEndCalled: () => boolean;
_getHeaders: () => Headers;
_getHeaders: () => HeaderWebAPI;
_getData: () => any;

@@ -148,0 +177,0 @@ _getJSONData: () => any;

@@ -38,2 +38,3 @@ /**

const utils = require('./utils');
const { createHeaders } = require('./headers');

@@ -77,3 +78,7 @@ const standardRequestOptions = [

}
mockRequest.headers = options.headers ? utils.convertKeysToLowerCase(options.headers) : {};
// Create headers using the Headers.js module
const originalHeaders = options.headers ? utils.convertKeysToLowerCase(options.headers) : {};
mockRequest.headers = createHeaders(originalHeaders);
mockRequest.body = options.body ? options.body : {};

@@ -80,0 +85,0 @@ mockRequest.query = options.query ? options.query : {};

2

package.json

@@ -5,3 +5,3 @@ {

"description": "Mock 'http' objects for testing Express, Next.js and Koa routing functions",
"version": "1.16.2",
"version": "1.17.0",
"homepage": "https://github.com/eugef/node-mocks-http",

@@ -8,0 +8,0 @@ "bugs": {