light-my-request
Advanced tools
@@ -30,2 +30,6 @@ import * as http from 'http' | ||
interface AbortSignal { | ||
readonly aborted: boolean; | ||
} | ||
interface InjectOptions { | ||
@@ -60,3 +64,5 @@ url?: string | { | ||
server?: http.Server | ||
cookies?: { [k: string]: string } | ||
cookies?: { [k: string]: string }, | ||
signal?: AbortSignal, | ||
Request?: object, | ||
} | ||
@@ -63,0 +69,0 @@ |
@@ -5,3 +5,3 @@ 'use strict' | ||
const { Readable } = require('stream') | ||
const { Readable, addAbortSignal } = require('stream') | ||
const util = require('util') | ||
@@ -133,2 +133,8 @@ const cookie = require('cookie') | ||
const signal = options.signal | ||
/* istanbul ignore if */ | ||
if (signal) { | ||
addAbortSignal(signal, this) | ||
} | ||
// we keep both payload and body for compatibility reasons | ||
@@ -135,0 +141,0 @@ let payload = options.payload || options.body || null |
{ | ||
"name": "light-my-request", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "Fake HTTP injection library", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,4 +7,4 @@ # Light my Request | ||
Injects a fake HTTP request/response into a node HTTP server for simulating server logic, writing tests, or debugging. | ||
Does not use a socket connection so can be run against an inactive server (server not in listen mode). | ||
Injects a fake HTTP request/response into a node HTTP server for simulating server logic, writing tests, or debugging. | ||
Does not use a socket connection so can be run against an inactive server (server not in listen mode). | ||
@@ -169,2 +169,3 @@ ## Example | ||
is called. It is only valid when not passing a callback. Defaults to `true`. | ||
- `signal` - An `AbortSignal` that may be used to abort an ongoing request. Requires Node v16+. | ||
- `Request` - Optional type from which the `request` object should inherit | ||
@@ -254,4 +255,4 @@ instead of `stream.Readable` | ||
## Acknowledgements | ||
This project has been forked from [`hapi/shot`](https://github.com/hapijs/shot) because we wanted to support *Node ≥ v4* and not only *Node ≥ v8*. | ||
All the credits before the commit [00a2a82](https://github.com/fastify/light-my-request/commit/00a2a82eb773b765003b6085788cc3564cd08326) goes to the `hapi/shot` project [contributors](https://github.com/hapijs/shot/graphs/contributors). | ||
This project has been forked from [`hapi/shot`](https://github.com/hapijs/shot) because we wanted to support *Node ≥ v4* and not only *Node ≥ v8*. | ||
All the credits before the commit [00a2a82](https://github.com/fastify/light-my-request/commit/00a2a82eb773b765003b6085788cc3564cd08326) goes to the `hapi/shot` project [contributors](https://github.com/hapijs/shot/graphs/contributors). | ||
Since the commit [db8bced](https://github.com/fastify/light-my-request/commit/db8bced10b4367731688c8738621d42f39680efc) the project will be maintained by the Fastify team. | ||
@@ -258,0 +259,0 @@ |
@@ -1837,1 +1837,18 @@ 'use strict' | ||
}) | ||
test('Can abort a request using AbortController/AbortSignal', (t) => { | ||
t.plan(1) | ||
const dispatch = function (req, res) {} | ||
const controller = new AbortController() | ||
const promise = inject(dispatch, { | ||
method: 'GET', | ||
url: 'http://example.com:8080/hello', | ||
signal: controller.signal | ||
}) | ||
controller.abort() | ||
const wanted = new Error('The operation was aborted') | ||
wanted.name = 'AbortError' | ||
t.rejects(promise, wanted) | ||
}, { skip: globalThis.AbortController == null }) |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
110747
0.75%3323
0.73%260
0.39%