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.4 to 0.0.5

36

lib/scheme.js

@@ -113,1 +113,37 @@ "use strict";

};
exports.jsonp = function (req, res) {
var p = parse(req.url),
code = 200,
callback = '',
query = qs.parse(p.query),
content = { "echo": true },
json = '';
if (query.callback) {
callback = query.callback;
delete query.callback;
}
if (req.body) {
query = req.body;
}
if (Object.keys(query).length) {
content = query;
}
if (!callback) {
code = 403;
json = JSON.stringify('{ "echo": "error, no callback" }');
} else {
json = callback + '(' + JSON.stringify(content) + ');';
}
res.writeHead(code, {
'Content-type': 'application/json'
});
res.end(json);
};

2

package.json

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

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

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

@@ -31,2 +31,3 @@ EchoEcho

* `json` - Send query parameters or POST parameters and get them back as JSON
* `jsonp` - Send query parameters or POST parameters and get them back as JSON (pass a GET param of `callback=[yourcallback]`

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

@@ -308,2 +308,72 @@ var vows = require('vows'),

},
"and get default jsonp": {
topic: function() {
fetch({
method: 'GET',
path: '/foo/bar/baz/echo/jsonp?callback=baz'
}, this.callback);
},
"with query body": function(topic) {
assert.equal(topic.code, 200);
assert.equal(topic.body, 'baz({"echo":true});');
}
},
"and post default jsonp": {
topic: function() {
fetch({
method: 'POST',
path: '/foo/bar/baz/echo/jsonp?callback=foo'
}, this.callback);
},
"with query body": function(topic) {
assert.equal(topic.code, 200);
assert.equal(topic.body, 'foo({"echo":true});');
}
},
"and get custom jsonp": {
topic: function() {
var self = this,
url = '/foo/bar/baz/echo/jsonp?callback=yo&foo=bar&baz=world';
fetch({
method: 'GET',
path: url
}, function(err, data) {
var q = parse(url);
var payload = qs.parse(q.query);
var callback = payload.callback;
delete payload.callback;
data.expected = callback + '(' + JSON.stringify(payload) + ');';
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 jsonp": {
topic: function() {
var self = this,
url = '/foo/bar/baz/echo/jsonp?callback=yoyo&foo=bar&baz=world&do=not';
fetch({
method: 'POST',
path: url
}, function(err, data) {
var q = parse(url);
var payload = qs.parse(q.query);
var callback = payload.callback;
delete payload.callback;
data.expected = callback + '(' + JSON.stringify(payload) + ');';
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": {

@@ -310,0 +380,0 @@ topic: function() {

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