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

echoecho

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

echoecho - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

25

lib/scheme.js

@@ -88,1 +88,26 @@ "use strict";

exports.delay = function (req, res) {
var delay = parseInt(req.url.split('/').pop(), 10),
seconds = (delay * 1000);
setTimeout(function () {
res.writeHead(200, headers);
res.end('waited for ' + delay + ' seconds');
}, seconds);
};
exports.json = function (req, res) {
var p = parse(req.url),
json = (p.query ? JSON.stringify(qs.parse(p.query)) : '{ "echo": true }');
if (req.body) {
json = JSON.stringify(req.body);
}
res.writeHead(200, {
'Content-type': 'application/json'
});
res.end(json);
};

2

package.json

@@ -5,3 +5,3 @@ {

"author": "Dav Glass <davglass@gmail.com>",
"version": "0.0.3",
"version": "0.0.4",
"dependencies": {

@@ -8,0 +8,0 @@ },

@@ -29,2 +29,4 @@ EchoEcho

* `status` - Special status route `echo/status/403` returns a `403`, all `http.STATUS_CODES` supported
* `delay` - Special delay route `echo/delay/2` returns a 200 delayed by 2 seconds.
* `json` - Send query parameters or POST parameters and get them back as JSON

@@ -31,0 +33,0 @@ Using in Your Server

var vows = require('vows'),
assert = require('assert'),
http = require('http'),
parse = require('url').parse,
qs = require('querystring');
echoecho = require('../lib/echo');

@@ -241,2 +243,78 @@

}
},
"and get default json": {
topic: function() {
fetch({
method: 'GET',
path: '/foo/bar/baz/echo/json'
}, this.callback);
},
"with query body": function(topic) {
assert.equal(topic.code, 200);
assert.equal(topic.body, '{ "echo": true }');
}
},
"and post default json": {
topic: function() {
fetch({
method: 'POST',
path: '/foo/bar/baz/echo/json'
}, this.callback);
},
"with query body": function(topic) {
assert.equal(topic.code, 200);
assert.equal(topic.body, '{ "echo": true }');
}
},
"and get custom json": {
topic: function() {
var self = this,
url = '/foo/bar/baz/echo/json?foo=bar&baz=world';
fetch({
method: 'GET',
path: url
}, function(err, data) {
var q = parse(url);
data.expected = JSON.stringify(qs.parse(q.query));
self.callback(err, data);
});
},
"with query body": function(topic) {
assert.equal(topic.code, 200);
assert.equal(topic.headers['content-type'], 'application/json');
assert.equal(topic.body, topic.expected);
}
},
"and post custom json": {
topic: function() {
var self = this,
url = '/foo/bar/baz/echo/json?foo=bar&baz=world&do=not';
fetch({
method: 'POST',
path: url
}, function(err, data) {
var q = parse(url);
data.expected = JSON.stringify(qs.parse(q.query));
self.callback(err, data);
});
},
"with query body": function(topic) {
assert.equal(topic.code, 200);
assert.equal(topic.headers['content-type'], 'application/json');
assert.equal(topic.body, topic.expected);
}
},
"and delay 3 seconds": {
topic: function() {
fetch({
method: 'GET',
path: '/foo/bar/baz/echo/delay/3'
}, this.callback);
},
"with query body": function(topic) {
assert.equal(topic.code, 200);
assert.equal(topic.body, 'waited for 3 seconds');
}
}

@@ -243,0 +321,0 @@ }

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