Socket
Socket
Sign inDemoInstall

request

Package Overview
Dependencies
0
Maintainers
0
Versions
126
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 1.2.0

._LICENSE

2

._package.json

@@ -1,4 +0,4 @@

Mac OS X  2��ATTR��"�"com.macromates.caret{
Mac OS X  2��ATTR���"�"com.macromates.caret{
column = 20;
line = 3;
}

@@ -0,4 +1,19 @@

// Copyright 2010-2011 Mikeal Rogers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
var http = require('http')
, url = require('url')
, sys = require('sys')
, qs = require('querystring')
;

@@ -78,6 +93,6 @@

if (options.uri.auth && !options.headers.authorization) {
options.headers.authorization = "Basic " + toBase64(options.uri.auth);
options.headers.authorization = "Basic " + toBase64(options.uri.auth.split(':').map(qs.unescape).join(':'));
}
if (options.proxy && options.proxy.auth && !options.headers['proxy-authorization']) {
options.headers['proxy-authorization'] = "Basic " + toBase64(options.proxy.auth);
options.headers['proxy-authorization'] = "Basic " + toBase64(options.proxy.auth.split(':').map(qs.unescape).join(':'));
}

@@ -90,6 +105,34 @@

if (options.body !== undefined) {
options.body = Buffer.isBuffer(options.body) ? options.body : new Buffer(options.body);
options.headers['content-length'] = options.body.length;
if (options.json) {
options.headers['content-type'] = 'application/json';
options.body = JSON.stringify(options.json);
} else if (options.multipart) {
options.body = '';
options.headers['content-type'] = 'multipart/related;boundary="frontier"';
if (!options.multipart.forEach) throw new Error('Argument error, options.multipart.');
options.multipart.forEach(function (part) {
var body = part.body;
if(!body) throw Error('Body attribute missing in multipart.');
delete part.body;
options.body += '--frontier\r\n';
Object.keys(part).forEach(function(key){
options.body += key + ': ' + part[key] + '\r\n'
})
options.body += '\r\n' + body + '\r\n';
})
options.body += '--frontier--'
}
if (options.body) {
if (!Buffer.isBuffer(options.body)) {
options.body = new Buffer(options.body);
}
if (options.body.length) {
options.headers['content-length'] = options.body.length;
} else {
throw new Error('Argument error, options.body.');
}
}
options.request = options.client.request(options.method, options.fullpath, options.headers);

@@ -157,3 +200,3 @@ options.request.addListener("response", function (response) {

options.method = 'POST';
if (!options.body && !options.requestBodyStream) {
if (!options.body && !options.requestBodyStream && !options.json && !options.multipart) {
sys.error("HTTP POST requests need a body or requestBodyStream");

@@ -165,3 +208,3 @@ }

options.method = 'PUT';
if (!options.body && !options.requestBodyStream) {
if (!options.body && !options.requestBodyStream && !options.json && !options.multipart) {
sys.error("HTTP PUT requests need a body or requestBodyStream");

@@ -173,3 +216,3 @@ }

options.method = 'HEAD';
if (options.body || options.requestBodyStream) {
if (options.body || options.requestBodyStream || options.json || options.multipart) {
throw new Error("HTTP HEAD requests MUST NOT include a request body.");

@@ -176,0 +219,0 @@ }

{ "name" : "request"
, "description" : "Simplified HTTP request client."
, "tags" : ["http", "simple", "util", "utility"]
, "version" : "1.1.1"
, "version" : "1.2.0"
, "author" : "Mikeal Rogers <mikeal.rogers@gmail.com>"

@@ -6,0 +6,0 @@ , "repository" :

@@ -9,2 +9,10 @@ # Request -- Simplified HTTP request method

Or from source:
<pre>
git clone git://github.com/mikeal/request.git
cd request
npm link .
</pre>
## Super simple to use

@@ -21,3 +29,5 @@

* `headers` - http headers, defaults to {}
* `body` - entity body for POST and PUT requests
* `body` - entity body for POST and PUT requests. Must be buffer or string.
* `json` - sets `body` but to JSON representation of value and adds `Content-type: application/json` header.
* `multipart` - (experimental) array of objects which contains their own headers and `body` attribute. Sends `multipart/related` request. See example below.
* `client` - existing http client object (when undefined a new one will be created and assigned to this property so you can keep around a reference to it if you would like use keep-alive on later request)

@@ -33,3 +43,3 @@ * `followRedirect` - follow HTTP 3xx responses as redirects. defaults to true.

Example:
Examples:
<pre>

@@ -44,2 +54,26 @@ var request = require('request');

It's also worth noting that the options argument will mutate. When following a redirect the uri values will change. After setting up a client options it will set the client property.
<pre>
var request = require('request');
var rand = Math.floor(Math.random()*100000000).toString();
request(
{ method: 'PUT'
, uri: 'http://mikeal.couchone.com/testjs/' + rand
, multipart:
[ { 'content-type': 'application/json'
, body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})
}
, { body: 'I am an attachment' }
]
}
, function (error, response, body) {
if(response.statusCode == 201){
console.log('document saved as: http://mikeal.couchone.com/testjs/'+ rand);
} else {
console.log('error: '+ response.statusCode);
console.log(body);
}
}
)
</pre>
It's also worth noting that the options argument will mutate. When following a redirect the uri values will change. After setting up client options it will set options.client.
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc