Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wreck

Package Overview
Dependencies
Maintainers
2
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wreck - npm Package Compare versions

Comparing version 8.0.1 to 9.0.0

15

lib/index.js

@@ -60,5 +60,8 @@ 'use strict';

const parsedBase = Url.parse(baseUrl);
const parsedPath = Url.parse(path);
if (parsedPath.host && parsedPath.protocol) {
return Url.format(parsedPath);
}
const parsedBase = Url.parse(baseUrl);
parsedBase.pathname = parsedBase.pathname + parsedPath.pathname;

@@ -76,5 +79,4 @@ parsedBase.pathname = parsedBase.pathname.replace(/[/]{2,}/g, '/');

Hoek.assert(options.payload === null || options.payload === undefined || typeof options.payload === 'string' ||
options.payload instanceof Stream || Buffer.isBuffer(options.payload),
'options.payload must be a string, a Buffer, or a Stream');
Hoek.assert(options.payload === undefined || typeof options.payload === 'string' || typeof options.payload === 'object',
'options.payload must be a string, a Buffer, a Stream, or an Object');

@@ -111,2 +113,7 @@ Hoek.assert((options.agent === undefined || options.agent === null) || (typeof options.rejectUnauthorized !== 'boolean'),

if (options.payload && typeof options.payload === 'object' && !(options.payload instanceof Stream) && !Buffer.isBuffer(options.payload)) {
options.payload = JSON.stringify(options.payload);
uri.headers['content-type'] = uri.headers['content-type'] || 'application/json';
}
const payloadSupported = (uri.method !== 'GET' && uri.method !== 'HEAD' && options.payload !== null && options.payload !== undefined);

@@ -113,0 +120,0 @@ if (payloadSupported &&

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ 'use strict';

{
"name": "wreck",
"description": "HTTP Client Utilities",
"version": "8.0.1",
"version": "9.0.0",
"repository": "git://github.com/hapijs/wreck",

@@ -6,0 +6,0 @@ "main": "lib/index",

@@ -15,5 +15,5 @@ ![wreck Logo](https://raw.github.com/hapijs/wreck/master/images/wreck.png)

```javascript
var Wreck = require('wreck');
const Wreck = require('wreck');
Wreck.get('https://google.com/', function (err, res, payload) {
Wreck.get('https://google.com/', (err, res, payload) => {
/* do stuff */

@@ -23,11 +23,19 @@ });

```javascript
const Wreck = require('wreck');
Wreck.post('https://posttestserver.com/post.php', { payload: { hello: 'post' } }, (err, res, payload) => {
/* do stuff */
});
```
### Advanced
```javascript
var Wreck = require('wreck');
const Wreck = require('wreck');
var method = 'GET'; // GET, POST, PUT, DELETE
var uri = '/';
var readableStream = Wreck.toReadableStream('foo=bar');
const method = 'GET'; // GET, POST, PUT, DELETE
const uri = '/';
const readableStream = Wreck.toReadableStream('foo=bar');
var wreck = Wreck.defaults({
const wreck = Wreck.defaults({
headers: { 'x-foo-bar': 123 }

@@ -37,3 +45,3 @@ });

// cascading example -- does not alter `wreck`
var wreckWithTimeout = wreck.defaults({
const wreckWithTimeout = wreck.defaults({
timeout: 5

@@ -43,11 +51,11 @@ });

// all attributes are optional
var options = {
baseUrl: "https://www.example.com",
payload: readableStream || 'foo=bar' || new Buffer('foo=bar'),
headers: { /* http headers */ },
const options = {
baseUrl: 'https://www.example.com',
payload: readableStream || 'foo=bar' || new Buffer('foo=bar'),
headers: { /* http headers */ },
redirects: 3,
beforeRedirect: function (redirectMethod, statusCode, location, resHeaders, redirectOptions, next) { return next() },
redirected: function (statusCode, location, req) {},
timeout: 1000, // 1 second, default: unlimited
maxBytes: 1048576, // 1 MB, default: unlimited
timeout: 1000, // 1 second, default: unlimited
maxBytes: 1048576, // 1 MB, default: unlimited
rejectUnauthorized: true || false,

@@ -59,3 +67,3 @@ downstreamRes: null,

var optionalCallback = function (err, res) {
const optionalCallback = (err, res) => {

@@ -65,3 +73,3 @@ /* handle err if it exists, in which case res will be undefined */

// buffer the response stream
Wreck.read(res, null, function (err, body) {
Wreck.read(res, null, (err, body) => {
/* do stuff */

@@ -71,3 +79,3 @@ });

var req = wreck.request(method, uri, options, optionalCallback);
const req = wreck.request(method, uri, options, optionalCallback);
```

@@ -92,3 +100,3 @@

- `socketPath` - `/path/to/unix/socket` for Server.
- `payload` - The request body as string, Buffer, or Readable Stream.
- `payload` - The request body as string, Buffer, Readable Stream, or an object that can be serialized using `JSON.stringify()`.
- `headers` - An object containing request headers.

@@ -225,4 +233,4 @@ - `redirects` - The maximum number of redirects to follow.

```javascript
var stream = Wreck.toReadableStream(new Buffer('Hello', 'ascii'), 'ascii');
var read = stream.read();
const stream = Wreck.toReadableStream(new Buffer('Hello', 'ascii'), 'ascii');
const read = stream.read();
// read -> 'Hello'

@@ -239,3 +247,3 @@ ```

```javascript
var result = Wreck.parseCacheControl('private, max-age=0, no-cache');
const result = Wreck.parseCacheControl('private, max-age=0, no-cache');
// result.private -> true

@@ -248,11 +256,14 @@ // result['max-age'] -> 0

Object that contains the agents for pooling connections for `http` and `https`. The properties are `http`, `https`, and
`httpsAllowUnauthorized` which is an `https` agent with `rejectUnauthorized` set to true. All agents have `maxSockets`
configured to `Infinity`. They are each instances of the node.js
[Agent](http://nodejs.org/api/http.html#http_class_http_agent) and expose the standard properties.
Object that contains the agents for pooling connections for `http` and `https`.
The properties are `http`, `https`, and `httpsAllowUnauthorized` which is an
`https` agent with `rejectUnauthorized` set to true. All agents have
`maxSockets` configured to `Infinity`. They are each instances of the node.js
[Agent](http://nodejs.org/api/http.html#http_class_http_agent) and expose the
standard properties.
For example, the following code demonstrates changing `maxSockets` on the `http` agent.
For example, the following code demonstrates changing `maxSockets` on the `http`
agent.
```js
var Wreck = require('wreck');
const Wreck = require('wreck');

@@ -270,3 +281,4 @@ Wreck.agents.http.maxSockets = 20;

- `uri` - the result of `Url.parse(uri)`. This will provide information about the resource requested. Also includes the headers and method.
- `uri` - the result of `Url.parse(uri)`. This will provide information about
the resource requested. Also includes the headers and method.
- `options` - the options passed into the request function. This will include

@@ -289,4 +301,4 @@ a payload if there is one.

- `start` - the time that the request was initiated
- `uri` - the result of `Url.parse(uri)`. This will provide information about the resource requested. Also includes
the headers and method.
- `uri` - the result of `Url.parse(uri)`. This will provide information about
the resource requested. Also includes the headers and method.

@@ -302,5 +314,5 @@ This event is useful for logging all requests that go through *wreck*. The error

The `EventEmitter` is attached to the `process` object under a `Symbol` with the
value of `'wreck'`. Therefore, if you want to capture a wreck event, after wreck
has been loaded, but in a module that doesn't require wreck, you can handle
events in the following way:
value of `'wreck'`. Therefore, if you want to capture a wreck event, after
wreck has been loaded, but in a module that doesn't require wreck, you can
handle events in the following way:

@@ -307,0 +319,0 @@ ```js

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