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

phin

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phin - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

LICENSE.md

83

lib/phin.js
"use strict";
const realHttp = require("http"),
https = require("https"),
url = require("url"),
qs = require("querystring"),
zlib = require("zlib"),
util = require("util");
const realHttp = require("http");
const https = require("https");
const url = require("url");
const qs = require("querystring");
const zlib = require("zlib");
const util = require("util");
/**
* @typedef Options Request options.
* @type {Object}
* @property {String} url The URL of the server to send a request to.
* @property {Boolean=} compressed Compress the request. Will overwrite the 'Accept-Encoding' header. Defaults to 'false'.
* @property {String=} protocol 'http:' or 'https:'. Inferred from the URL if not present.
* @property {String=} hostname A domain name or IP address of the server to issue the request to. Inferred from the URL if not present.
* @property {Number=} port The port to send the request to. Defaults to 80 on HTTP and 443 on HTTPS.
* @property {String=} localAddress Local interface to bind for network connections.
* @property {String=} socketPath Unix Domain Socket (use one of host:port or socketPath).
* @property {String=} method The request method (ex. GET, POST, etc.). Defaults to "GET".
* @property {String=} path Request path. Inferred from the URL if not present.
* @property {Object=} headers An object with request headers.
* @property {String=} auth Basic authentication (ex. ethan:letmein). Inferred from the URL if not present.
* @property {Number=} timeout The socket timeout, in milliseconds.
* @property {(Buffer|Object)=} data The data to send to the client. JSON.stringify is automatically called on objects when the 'Content-Type' or 'content-type' header is 'application/json' and querystring.stringify is called on objects when the 'Content-Type' or 'content-type' header is 'x/www-url-form-encoded'.
*/
* phin options object
* @typedef {Object} phinOptions
* @property {string} url - URL to request (autodetect infers from this URL)
* @property {string} [method=GET] - Request method ('GET', 'POST', etc.)
* @property {Object} [headers={}] - Request headers
* @property {string} [auth=autodetect] - Request authentiction in "user:password" format
* @property {string} [hostname=autodetect] - URL hostname
* @property {Number} [port=autodetect] - URL port
* @property {string} [path=autodetect] - URL path
*/
/**
* @typedef IncomingMessage The incoming message from the server.
* @type {Object}
* @property {Buffer} body The data sent by the server.
* @property {Object} headers Response headers.
* @property {String} httpVersion HTTP version being used.
* @property {Object} rawHeaders The raw request/response headers list exactly as they were received.
* @property {String[]} rawTrailers The raw request/response trailer keys and values exactly as they were received.
* @property {net.Socket} socket The [net.Socket]{@link https://nodejs.org/api/net.html#net_class_net_socket} object associated with the connection.
* @property {Number} statusCode The 3-digit HTTP response status code (eg. 404).
* @property {String} statusMessage The HTTP response status message (ex. OK, Internal Server Error).
* @property {{String:String}} trailers The request/response trailers object.
*/
* Response data callback
* @callback phinResponseCallback
* @param {?(Error|string)} error - Error if any occurred in request, otherwise null.
* @param {?http.serverResponse} phinResponse - phin response object. Like <a href="https://nodejs.org/api/http.html#http_class_http_serverresponse">http.ServerResponse</a> but has a body property containing response body
*/
/**
* @callback PhinCallback Called when data is recieved from server.
* @param {Error} err An error that occured. Not present if no error occured.
* @param {IncomingMessage} res The response from the server.
*/
/**
* Sends a request to a server.
* @param {Options|String} opts Request options or URL.
* @param {PhinCallback} cb Called when data is recieved from server.
*/
* Sends an HTTP request
* @param {phinOptions|string} options - phin options object (or string for auto-detection)
* @param {phinResponseCallback} [callback=null] - Callback to which data is sent upon request completion
* @param {Object} [httpModule=require('http')] - HTTP module injection (for testing)
*/
const phin = (opts, cb, injectedHttp) => {
if (typeof(opts) !== "string" && !opts.hasOwnProperty("url")) {
throw new Error("Missing url option from options for request method.");
if (typeof(opts) !== "string") {
if (!opts.hasOwnProperty("url")) {
throw new Error("Missing url option from options for request method.");
}
}

@@ -78,3 +62,3 @@

if (options.compressed) {
if (options.compressed === true) {
options.headers["accept-encoding"] = "gzip, deflate";

@@ -86,3 +70,3 @@ }

var stream = res;
if (options.compressed) {
if (options.compressed === true) {
if (res.headers["content-encoding"] === "gzip") {

@@ -117,5 +101,4 @@ stream = res.pipe(zlib.createGunzip());

default:
const err = new Error("Invalid / unknown URL protocol. Expected HTTP or HTTPS.");
if (cb) {
cb(err, null);
cb(new Error("Invalid / unknown URL protocol. Expected HTTP or HTTPS."), null);
}

@@ -122,0 +105,0 @@ return;

{
"name": "phin",
"version": "2.1.0",
"version": "2.2.0",
"description": "Ultra-simple, lightweight, dependency-free Node.JS HTTP request client",

@@ -23,3 +23,3 @@ "main": "index.js",

"author": "Ethan Davis",
"license": "MIT",
"license": "SEE LICENSE IN LICENSE.md",
"bugs": {

@@ -26,0 +26,0 @@ "url": "https://github.com/FuturisticCake/phin/issues"

@@ -5,10 +5,8 @@ # phin

<img src="http://i.imgur.com/SSBM2Pw.png" width="200" alt="phin logo"></img>
<img src="http://i.imgur.com/SSBM2Pw.png" width="100" alt="phin logo"/>
[![phin on NPM](https://nodei.co/npm/phin.png)](https://www.npmjs.com/package/phin)
---
[![phin - Downloads Total](https://img.shields.io/npm/dt/phin.svg)](https://www.npmjs.com/package/phin) [![phin - Version](https://img.shields.io/npm/v/phin.svg)](https://www.npmjs.com/package/phin) [![phin - License](https://img.shields.io/npm/l/phin.svg)](https://www.npmjs.com/package/phin) [![phin - Github Stars](https://img.shields.io/github/stars/FuturisticCake/phin.svg?style=social&label=Star)](https://github.com/FuturisticCake/phin)
[Full documentation](https://futuristiccake.github.io/phin/) | [GitHub](https://github.com/FuturisticCake/phin) | [NPM](https://www.npmjs.com/package/phin)
---
## Simple Usage

@@ -35,3 +33,3 @@ For a simple GET request.

### GET request with custom headers
### GET request with added headers

@@ -92,13 +90,4 @@ ```javascript

See [the documentation](https://futuristiccake.github.io/phin/global.html).
Note that `phin` has [`util.promisify`](https://nodejs.org/dist/latest-v8.x/docs/api/util.html#util_util_promisify_original) support.
See [the phin documentation](https://futuristiccake.github.io/phin/).
## License (MIT)
Copyright 2017 Ethan Davis
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Note that `phin` has [`util.promisify`](https://nodejs.org/dist/latest-v8.x/docs/api/util.html#util_util_promisify_original) support.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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