Socket
Socket
Sign inDemoInstall

httpsnippet

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

httpsnippet - npm Package Compare versions

Comparing version 1.0.0-beta.4 to 1.0.0-beta.5

5

package.json
{
"version": "1.0.0-beta.4",
"version": "1.0.0-beta.5",
"name": "httpsnippet",

@@ -13,3 +13,3 @@ "description": "HTTP Request snippet generator for *most* languages",

},
"config":{
"config": {
"blanket": {

@@ -40,4 +40,5 @@ "pattern": "src"

"debug": "^2.1.1",
"har-validator": "^1.1.2",
"requireindex": "^1.1.0"
}
}

79

src/index.js

@@ -8,2 +8,3 @@ 'use strict';

var url = require('url');
var validate = require('har-validator');
var util = require('util');

@@ -15,45 +16,59 @@

// construct query string object
this.source.queryObj = {};
this.source.headersObj = {};
// add optional properties to make validation successful
this.source.httpVersion = this.source.httpVersion || 'HTTP/1.1';
this.source.queryString = this.source.queryString || [];
this.source.headers = this.source.headers || [];
this.source.cookies = this.source.cookies || [];
this.source.postData = this.source.postData || {};
this.source.postData.mimeType = this.source.postData.mimeType || 'application/x-www-form-urlencoded';
if (this.source.url === undefined) {
throw new Error('a request url is required');
}
this.source.bodySize = 0;
this.source.headersSize = 0;
this.source.postData.size = 0;
// construct query objects
if (this.source.queryString && this.source.queryString.length) {
debug('queryString found, constructing queryString pair map');
validate.request(this.source, function (err, valid) {
if (!valid) {
throw err;
}
this.source.queryString.map(mapper(this.source.queryObj));
}
// construct query string object
this.source.queryObj = {};
this.source.headersObj = {};
// construct headers objects
if (this.source.headers && this.source.headers.length) {
debug('headers found, constructing header pair map');
// construct query objects
if (this.source.queryString && this.source.queryString.length) {
debug('queryString found, constructing queryString pair map');
this.source.headers.map(mapper(this.source.headersObj));
}
this.source.queryString.map(mapper(this.source.queryObj));
}
// deconstruct the uri
this.source.uriObj = url.parse(this.source.url, true, true);
// construct headers objects
if (this.source.headers && this.source.headers.length) {
debug('headers found, constructing header pair map');
// merge all possible queryString values
this.source.queryString = util._extend(this.source.uriObj.query, this.source.queryObj);
this.source.headers.map(mapper(this.source.headersObj));
}
// reset uriObj values for a clean url
this.source.uriObj.query = null;
this.source.uriObj.search = null;
this.source.uriObj.path = this.source.uriObj.pathname;
// deconstruct the uri
this.source.uriObj = url.parse(this.source.url, true, true);
// keep the base url clean of queryString
this.source.url = url.format(this.source.uriObj);
// merge all possible queryString values
this.source.queryString = util._extend(this.source.uriObj.query, this.source.queryObj);
// update the uri object
this.source.uriObj.query = this.source.queryString;
this.source.uriObj.search = qs.stringify(this.source.queryString);
this.source.uriObj.path = this.source.uriObj.pathname + '?' + this.source.uriObj.search;
// reset uriObj values for a clean url
this.source.uriObj.query = null;
this.source.uriObj.search = null;
this.source.uriObj.path = this.source.uriObj.pathname;
// construct a full url
this.source.fullUrl = url.format(this.source.uriObj);
// keep the base url clean of queryString
this.source.url = url.format(this.source.uriObj);
// update the uri object
this.source.uriObj.query = this.source.queryString;
this.source.uriObj.search = qs.stringify(this.source.queryString);
this.source.uriObj.path = this.source.uriObj.pathname + '?' + this.source.uriObj.search;
// construct a full url
this.source.fullUrl = url.format(this.source.uriObj);
}.bind(this));
};

@@ -60,0 +75,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