New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lightning-request

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lightning-request - npm Package Compare versions

Comparing version

to
0.2.1-beta.0

lib/worker.js

10

lib/request.js

@@ -29,3 +29,3 @@ const http = require('http');

data &&
Object.keys(data).forEach(key => {
Object.keys(data).forEach((key) => {
parsedUrl.searchParams.append(key, data[key]);

@@ -69,3 +69,3 @@ });

const resHandler = res => {
const resHandler = (res) => {
const statusCode = res.statusCode;

@@ -78,3 +78,3 @@ let response = new Response({

res.on('data', chunk => {
res.on('data', (chunk) => {
response.addChunk(chunk);

@@ -92,3 +92,3 @@ });

});
res.on('error', err => {
res.on('error', (err) => {
reject(enhanceError(err, options, null, req));

@@ -108,3 +108,3 @@ });

// Handle errors
req.on('error', err => {
req.on('error', (err) => {
if (req.aborted) {

@@ -111,0 +111,0 @@ return;

@@ -1,18 +0,8 @@

const spawnSync = require('child_process').spawnSync;
const init = require('sync-rpc');
const remote = init(require.resolve('./worker'));
function syncRequest(options = {}) {
var args = [__dirname + '/sync.js', JSON.stringify(options)];
var proc = spawnSync(process.argv[0], args, { encoding: 'utf8' });
if (proc.stdout) {
return JSON.parse(proc.stdout);
} else if (proc.stderr) {
const resp = JSON.parse(proc.stderr);
const err = new Error(resp.message);
err.stack = resp.stack;
throw err;
}
return remote(options);
}
module.exports = syncRequest;
{
"name": "lightning-request",
"version": "0.2.0",
"version": "0.2.1-beta.0",
"description": "⚡⚡⚡Lightweight Node.js HTTP client based on http. ",
"main": "index.js",
"scripts": {
"test": "nyc ava --verbose --no-cache",
"test:watch": "nyc ava --verbose --watch --no-cache",
"test": "nyc ava --verbose --no-cache --timeout=1m",
"test:watch": "nyc ava --verbose --watch --no-cache --timeout=1m",
"report": "nyc report --reporter=html && open coverage/index.html",

@@ -31,3 +31,6 @@ "release": "sh release.sh"

},
"homepage": "https://github.com/node-labx/lightning-request"
"homepage": "https://github.com/node-labx/lightning-request",
"dependencies": {
"sync-rpc": "^1.3.6"
}
}
const test = require('ava');
const request = require('../index');
test('request#参数 url 校验', async t => {
test('参数 url 校验', async (t) => {
try {

@@ -12,3 +12,13 @@ await request();

test('request#HTTP to HTTPS', async t => {
test('请求协议校验', async (t) => {
try {
await request({
url: 'ftp://api.github.com/repos/node-labx/lightning-request',
});
} catch (error) {
t.is(error.message, 'Protocol "ftp:" not supported. Expected "http:" or "https:"');
}
});
test('HTTP to HTTPS', async (t) => {
const resp = await request({

@@ -20,3 +30,3 @@ url: 'http://api.github.com/repos/node-labx/lightning-request',

test('request#简单 HTTP GET 请求 ', async t => {
test('简单 HTTP GET 请求 ', async (t) => {
const resp = await request({

@@ -30,3 +40,3 @@ url: 'https://api.github.com/repos/node-labx/lightning-request',

test('request#HTTP GET 请求带 Query 参数', async t => {
test('HTTP GET 请求带 Query 参数', async (t) => {
try {

@@ -33,0 +43,0 @@ const resp = await request({

const test = require('ava');
const { syncRequest } = require('../index');
const syncRequest = require('../lib/syncRequest');
test('syncRequest#参数 url 校验', t => {
test('参数 url 校验', (t) => {
try {

@@ -12,3 +12,13 @@ syncRequest();

test('syncRequest#HTTP to HTTPS', t => {
test('请求协议校验', (t) => {
try {
syncRequest({
url: 'ftp://api.github.com/repos/node-labx/lightning-request',
});
} catch (error) {
t.is(error.message, 'Protocol "ftp:" not supported. Expected "http:" or "https:"');
}
});
test('HTTP to HTTPS', (t) => {
const resp = syncRequest({

@@ -20,3 +30,3 @@ url: 'http://api.github.com/repos/node-labx/lightning-request',

test('syncRequest#简单 HTTP GET 请求 ', t => {
test('简单 HTTP GET 请求 ', (t) => {
const resp = syncRequest({

@@ -28,1 +38,15 @@ url: 'https://api.github.com/repos/node-labx/lightning-request',

});
test('HTTP GET 请求带 Query 参数', (t) => {
try {
const resp = syncRequest({
url: 'https://api.github.com/search/repositories',
data: {
q: 'lightning-request',
},
});
t.is(resp.statusCode, 200);
} catch (error) {
console.log(error);
}
});