Socket
Socket
Sign inDemoInstall

got

Package Overview
Dependencies
16
Maintainers
2
Versions
175
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.0 to 2.2.0

49

index.js

@@ -6,3 +6,3 @@ 'use strict';

var zlib = require('zlib');
var PassThrough = require('stream').PassThrough;
var duplexify = require('duplexify');
var assign = require('object-assign');

@@ -12,3 +12,3 @@ var read = require('read-all-stream');

module.exports = function (url, opts, cb) {
function got(url, opts, cb) {
if (typeof opts === 'function') {

@@ -30,4 +30,4 @@ // if `cb` has been specified but `opts` has not

if (body && opts.method === undefined) {
opts.method = 'POST';
if (body) {
opts.method = opts.method || 'POST';
}

@@ -39,3 +39,3 @@

if (!cb) {
proxy = new PassThrough();
proxy = duplexify();

@@ -93,3 +93,3 @@ // forward errors on the stream

if (proxy) {
res.on('error', proxy.emit.bind(proxy, 'error')).pipe(proxy);
proxy.setReadable(res);
return;

@@ -105,8 +105,20 @@ }

if (!body) {
req.end();
if (!proxy) {
req.end(body);
return;
}
req.write(body);
if (body) {
proxy.write = function () {
throw new Error('got\'s stream is not writable when options.body is used');
};
req.end(body);
return;
}
if (opts.method === 'POST' || opts.method === 'PUT' || opts.method === 'PATCH') {
proxy.setWritable(req);
return;
}
req.end();

@@ -118,2 +130,19 @@ };

return proxy;
};
}
[
'get',
'post',
'put',
'patch',
'head',
'delete'
].forEach(function (el) {
got[el] = function (url, opts, cb) {
opts = opts || {};
opts.method = el.toUpperCase();
return got(url, opts, cb);
};
});
module.exports = got;
{
"name": "got",
"version": "2.1.0",
"version": "2.2.0",
"description": "Simplified HTTP/HTTPS requests",

@@ -16,3 +16,3 @@ "license": "MIT",

"scripts": {
"test": "mocha"
"test": "mocha --timeout 50000"
},

@@ -35,2 +35,3 @@ "files": [

"dependencies": {
"duplexify": "^3.2.0",
"object-assign": "^2.0.0",

@@ -37,0 +38,0 @@ "read-all-stream": "^0.1.0",

@@ -30,4 +30,8 @@ # got [![Build Status](https://travis-ci.org/sindresorhus/got.svg?branch=master)](https://travis-ci.org/sindresorhus/got)

// Stream mode.
got('http://todomvc.com').pipe(fs.createWriteStream('index.html'));
// For POST and PUT methods got returns WritableStream
fs.createReadStream('index.html').pipe(got.post('http://todomvc.com'));
```

@@ -67,2 +71,4 @@

This option and stream mode are mutually exclusive.
##### options.timeout

@@ -88,3 +94,12 @@

#### got.get(url, [options], [callback])
#### got.post(url, [options], [callback])
#### got.put(url, [options], [callback])
#### got.patch(url, [options], [callback])
#### got.head(url, [options], [callback])
#### got.delete(url, [options], [callback])
Sets `options.method` to the method name and makes a request.
## Related

@@ -91,0 +106,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc