Socket
Socket
Sign inDemoInstall

needle

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

needle - npm Package Compare versions

Comparing version 0.4.8 to 0.4.9

31

lib/needle.js

@@ -66,3 +66,3 @@ //////////////////////////////////////////

parse_response: options.parse === false ? false : true,
follow: options.follow === false ? 0 : options.follow || 10, // 10 by default
follow: options.follow === true ? 10 : typeof options.follow == 'number' ? options.follow : 0,
timeout: (typeof options.timeout == 'number') ? options.timeout : 10000

@@ -91,3 +91,3 @@ }

if (options.username && options.password){
if (options.username && options.password) {
var b = new Buffer([options.username, options.password].join(':'));

@@ -98,8 +98,6 @@ var auth_header = options.proxy ? 'Proxy-Authorization' : 'Authorization';

if (data){
if (options.multipart){
if (data) {
if (options.multipart) {
var boundary = options.boundary || this.default_boundary;
return multipart.build(data, boundary, function(err, body){
if (err) throw(err);

@@ -109,11 +107,11 @@ config.headers['Content-Type'] = 'multipart/form-data; boundary=' + boundary;

self.send_request(1, method, uri, config, body, callback);
});
} else {
var content_type = options.json ? 'application/json' : 'application/x-www-form-urlencoded';
var post_data = (typeof(data) === 'string') ? data :
options.json ? JSON.stringify(data) : stringify(data);
} else {
post_data = (typeof(data) === "string") ? data : stringify(data);
config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
config.headers['Content-Type'] = content_type;
config.headers['Content-Length'] = post_data.length;
}
}

@@ -134,3 +132,3 @@

opts.headers = config.headers;
opts.headers["Host"] = proxy ? url.parse(uri).hostname : remote.hostname;
opts.headers['Host'] = proxy ? url.parse(uri).hostname : remote.hostname;

@@ -254,2 +252,7 @@ return opts;

var is_valid_data = function(obj) {
return typeof obj === 'string'
|| (obj.toString() === '[object Object]' && Object.keys(obj).length > 0);
}
exports.head = function(uri, options, callback){

@@ -264,3 +267,3 @@ return Needle.request(uri, 'HEAD', null, options, callback);

exports.post = function(uri, data, options, callback){
if (!data || typeof data == 'function') throw('POST request expects data.');
if (!data || !is_valid_data(data)) throw('POST request expects data.');
return Needle.request(uri, 'POST', data, options, callback);

@@ -270,3 +273,3 @@ }

exports.put = function(uri, data, options, callback){
if (!data || typeof data == 'function') throw('PUT request expects data.');
if (!data || !is_valid_data(data)) throw('PUT request expects data.');
return Needle.request(uri, 'PUT', data, options, callback);

@@ -273,0 +276,0 @@ }

{
"name": "needle"
, "version": "0.4.8"
, "version": "0.4.9"
, "description": "Tiny yet feature-packed HTTP client. With multipart, charset decoding and proxy support."

@@ -5,0 +5,0 @@ , "keywords": ["http", "https", "simple", "client", "multipart", "upload", "proxy", "deflate", "timeout", "charset", "iconv"]

var http = require('http'),
https = require('https'),
url = require('url');
var port = 1234,
log = true,
request_auth = false;
var port = 1234;
var log = true;
http.createServer(function(request, response) {
console.log(request.headers);
console.log("Got request: " + request.url);
console.log("Forwarding request to " + request.headers['host']);
if (request_auth) {
if (!request.headers['proxy-authorization']) {
response.writeHead(407, {'Proxy-Authenticate': 'Basic realm="proxy.com"'})
return response.end('Hello.');
}
}
var remote = url.parse(request.url);

@@ -16,0 +23,0 @@ var protocol = remote.protocol == 'https:' ? https : http;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc