Socket
Socket
Sign inDemoInstall

typed-rest-client

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typed-rest-client - npm Package Compare versions

Comparing version 0.12.0 to 0.13.0

3

HttpClient.d.ts

@@ -0,1 +1,2 @@

/// <reference types="node" />
import url = require("url");

@@ -50,2 +51,4 @@ import http = require("http");

private _httpProxyBypassHosts;
private _allowRedirects;
private _maxRedirects;
private _certConfig;

@@ -52,0 +55,0 @@ private _ca;

63

HttpClient.js

@@ -0,4 +1,4 @@

"use strict";
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -9,5 +9,6 @@ return new (P || (P = Promise))(function (resolve, reject) {

function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const url = require("url");

@@ -47,2 +48,3 @@ const http = require("http");

})(HttpCodes = exports.HttpCodes || (exports.HttpCodes = {}));
const HttpRedirectCodes = [HttpCodes.MovedPermanently, HttpCodes.ResourceMoved, HttpCodes.TemporaryRedirect, HttpCodes.PermanentRedirect];
class HttpClientResponse {

@@ -70,5 +72,12 @@ constructor(message) {

exports.isHttps = isHttps;
var EnvironmentVariables;
(function (EnvironmentVariables) {
EnvironmentVariables["HTTP_PROXY"] = "HTTP_PROXY";
EnvironmentVariables["HTTPS_PROXY"] = "HTTPS_PROXY";
})(EnvironmentVariables || (EnvironmentVariables = {}));
class HttpClient {
constructor(userAgent, handlers, requestOptions) {
this._ignoreSslError = false;
this._allowRedirects = true;
this._maxRedirects = 50;
this.userAgent = userAgent;

@@ -100,2 +109,8 @@ this.handlers = handlers;

}
if (requestOptions.allowRedirects != null) {
this._allowRedirects = requestOptions.allowRedirects;
}
if (requestOptions.maxRedirects != null) {
this._maxRedirects = Math.max(requestOptions.maxRedirects, 0);
}
}

@@ -133,16 +148,24 @@ }

request(verb, requestUrl, data, headers) {
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
try {
var info = this._prepareRequest(verb, requestUrl, headers);
let res = yield this._requestRaw(info, data);
// TODO: check 401 if handled
// TODO: retry support
resolve(res);
return __awaiter(this, void 0, void 0, function* () {
let info = this._prepareRequest(verb, requestUrl, headers);
let response = yield this._requestRaw(info, data);
let redirectsRemaining = this._maxRedirects;
while (HttpRedirectCodes.indexOf(response.message.statusCode) != -1
&& this._allowRedirects
&& redirectsRemaining > 0) {
const redirectUrl = response.message.headers["location"];
if (!redirectUrl) {
// if there's no location to redirect to, we won't
break;
}
// we need to finish reading the response before reassigning response
// which will leak the open socket.
yield response.readBody();
// let's make the request with the new redirectUrl
info = this._prepareRequest(verb, redirectUrl, headers);
response = yield this._requestRaw(info, data);
redirectsRemaining--;
}
catch (err) {
// only throws in truly exceptional cases (connection, can't resolve etc...)
// responses from the server do not throw
reject(err);
}
}));
return response;
});
}

@@ -197,11 +220,13 @@ _requestRaw(info, data) {

// fallback to http_proxy and https_proxy env
let https_proxy = process.env[EnvironmentVariables.HTTPS_PROXY];
let http_proxy = process.env[EnvironmentVariables.HTTP_PROXY];
if (!proxyConfig) {
if (process.env.HTTPS_PROXY && usingSsl) {
if (https_proxy && usingSsl) {
proxyConfig = {
proxyUrl: process.env.HTTPS_PROXY
proxyUrl: https_proxy
};
}
else if (process.env.HTTP_PROXY) {
else if (http_proxy) {
proxyConfig = {
proxyUrl: process.env.HTTP_PROXY
proxyUrl: http_proxy
};

@@ -208,0 +233,0 @@ }

@@ -1,2 +0,2 @@

/// <reference path="../typings/index.d.ts" />
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

@@ -22,2 +22,4 @@ export interface IHeaders {

cert?: ICertConfiguration;
allowRedirects?: boolean;
maxRedirects?: number;
}

@@ -24,0 +26,0 @@ export interface IProxyConfiguration {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
;
{
"name": "typed-rest-client",
"version": "0.12.0",
"description": "Node Rest and Http Clients with typings for use with TypeScript",
"main": "./RestClient.js",
"scripts": {
"build": "node make.js build",
"test": "node make.js test",
"samples": "node make.js samples"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Microsoft/typed-rest-client.git"
},
"keywords": [
"rest",
"http",
"client",
"typescript",
"node"
],
"author": "Microsoft Corporation",
"license": "MIT",
"bugs": {
"url": "https://github.com/Microsoft/typed-rest-client/issues"
},
"homepage": "https://github.com/Microsoft/typed-rest-client#readme",
"devDependencies": {
"shelljs": "0.7.0",
"typescript": "2.1.4"
},
"dependencies": {
"tunnel": "0.0.4",
"underscore": "1.8.3"
}
}
"name": "typed-rest-client",
"version": "0.13.0",
"description": "Node Rest and Http Clients for use with TypeScript",
"main": "./RestClient.js",
"scripts": {
"build": "node make.js build",
"test": "node make.js test",
"samples": "node make.js samples"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Microsoft/typed-rest-client.git"
},
"keywords": [
"rest",
"http",
"client",
"typescript",
"node"
],
"author": "Microsoft Corporation",
"license": "MIT",
"bugs": {
"url": "https://github.com/Microsoft/typed-rest-client/issues"
},
"homepage": "https://github.com/Microsoft/typed-rest-client#readme",
"devDependencies": {
"typescript": "2.4.2",
"node": "^8.0.19",
"@types/node": "^8.0.19",
"shelljs": "0.7.6",
"@types/shelljs": "0.7.4",
"mocha": "^3.2.0",
"@types/mocha": "^2.2.41"
},
"dependencies": {
"tunnel": "0.0.4",
"underscore": "1.8.3"
}
}

@@ -45,32 +45,2 @@ # Typed Rest and Http Client with TypeScript Typings

### Typings
Typings (.d.ts) are distributed with the client, so intellisense and compile support just works from `tsc` and [vscode]()
## Pre-Requisites
Pre-req: prefer [Node 6.9.3 LTS](https://nodejs.org), minimum [Node >= 4.4.7 LTS](https://nodejs.org)
Typings: `npm install typings -g`
Once (or when dependencies change):
```bash
npm install
typings install
```
## Build
```bash
npm run build
```
## Running Samples
Run samples:
```bash
$ npm run samples
```
## Contributing

@@ -77,0 +47,0 @@

@@ -0,1 +1,2 @@

/// <reference types="node" />
import httpm = require('./HttpClient');

@@ -2,0 +3,0 @@ import ifm = require("./Interfaces");

@@ -0,4 +1,4 @@

"use strict";
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -9,5 +9,6 @@ return new (P || (P = Promise))(function (resolve, reject) {

function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const httpm = require("./HttpClient");

@@ -14,0 +15,0 @@ const util = require("./Util");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const url = require("url");

@@ -3,0 +4,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