Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
29ee46b3a2 | |||
18dd110d4e | |||
fa93f13306 | |||
81694cf58c | |||
fdd1c7cdb3 | |||
40f330791f |
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartrequest",
|
"name": "@pushrocks/smartrequest",
|
||||||
"version": "2.0.17",
|
"version": "2.0.20",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@pushrocks/smartrequest",
|
"name": "@pushrocks/smartrequest",
|
||||||
"version": "2.0.17",
|
"version": "2.0.20",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartpromise": "^3.1.7",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartrequest",
|
"name": "@push.rocks/smartrequest",
|
||||||
"version": "2.0.17",
|
"version": "2.0.20",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "dropin replacement for request",
|
"description": "dropin replacement for request",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
1203
pnpm-lock.yaml
generated
1203
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartrequest',
|
name: '@push.rocks/smartrequest',
|
||||||
version: '2.0.17',
|
version: '2.0.20',
|
||||||
description: 'dropin replacement for request'
|
description: 'dropin replacement for request'
|
||||||
}
|
}
|
||||||
|
@ -5,3 +5,4 @@ export type { ISmartRequestOptions } from './smartrequest.interfaces.js';
|
|||||||
export * from './smartrequest.jsonrest.js';
|
export * from './smartrequest.jsonrest.js';
|
||||||
export * from './smartrequest.binaryrest.js';
|
export * from './smartrequest.binaryrest.js';
|
||||||
export * from './smartrequest.formdata.js';
|
export * from './smartrequest.formdata.js';
|
||||||
|
export * from './smartrequest.stream.js';
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
import * as plugins from './smartrequest.plugins.js';
|
import * as plugins from './smartrequest.plugins.js';
|
||||||
import * as interfaces from './smartrequest.interfaces.js';
|
import * as interfaces from './smartrequest.interfaces.js';
|
||||||
|
|
||||||
import { IncomingMessage } from 'http';
|
export interface IExtendedIncomingMessage extends plugins.http.IncomingMessage {
|
||||||
|
|
||||||
export interface IExtendedIncomingMessage extends IncomingMessage {
|
|
||||||
body: any;
|
body: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildUtf8Response = (
|
const buildUtf8Response = (
|
||||||
incomingMessageArg: IncomingMessage,
|
incomingMessageArg: plugins.http.IncomingMessage,
|
||||||
autoJsonParse = true
|
autoJsonParse = true
|
||||||
): Promise<IExtendedIncomingMessage> => {
|
): Promise<IExtendedIncomingMessage> => {
|
||||||
const done = plugins.smartpromise.defer<IExtendedIncomingMessage>();
|
const done = plugins.smartpromise.defer<IExtendedIncomingMessage>();
|
||||||
|
17
ts/smartrequest.stream.ts
Normal file
17
ts/smartrequest.stream.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import * as plugins from './smartrequest.plugins.js';
|
||||||
|
import * as interfaces from './smartrequest.interfaces.js';
|
||||||
|
import { request } from './smartrequest.request.js';
|
||||||
|
|
||||||
|
export const getStream = async (
|
||||||
|
urlArg: string,
|
||||||
|
optionsArg: interfaces.ISmartRequestOptions = {}
|
||||||
|
): Promise<plugins.http.IncomingMessage> => {
|
||||||
|
try {
|
||||||
|
// Call the existing request function with responseStreamArg set to true.
|
||||||
|
const responseStream = await request(urlArg, optionsArg, true);
|
||||||
|
return responseStream;
|
||||||
|
} catch (err) {
|
||||||
|
console.error('An error occurred while getting the stream:', err);
|
||||||
|
throw err; // Rethrow the error to be handled by the caller.
|
||||||
|
}
|
||||||
|
};
|
Reference in New Issue
Block a user