From e1a5b098745f6d31e0d40ffe66c841148becc8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20G=C3=BCnther?= Date: Tue, 5 May 2015 10:17:40 +0200 Subject: [PATCH] Added support for proxy agent --- README.md | 26 ++++++++++++++++++++++++++ lib/client.js | 7 +++++-- package.json | 3 ++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 365939d..4b6bf96 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,32 @@ var options = { dogapi.initialize(options); ``` +### HTTPS Proxy + +If you are behind a proxy you need to a proxy agent. You can use the https proxy agent from +http://blog.vanamco.com/connecting-via-proxy-node-js/ if you like. +To configure dogapi with the agent just add it to the options. + +```javascript +var dogapi = require("dogapi"); + +//Code from http://blog.vanamco.com/connecting-via-proxy-node-js/ +var HttpsProxyAgent = require("./httpsproxyagent"); + +var agent = new HttpsProxyAgent({ + proxyHost: "MY_PROXY_HOST", + proxyPort: 3128 +}); + +var options = { + api_key: "YOUR_KEY_HERE", + app_key: "YOUR_KEY_HERE", + proxy_agent: agent +}; + +dogapi.initialize(options); +``` + ## CLI Usage `dogapi` now ships with a command line interface `dogapi`. To use it you diff --git a/lib/client.js b/lib/client.js index 3e91e40..cb3cbb4 100644 --- a/lib/client.js +++ b/lib/client.js @@ -3,7 +3,6 @@ var https = require("https"); var url = require("url"); var util = require("util"); - /*section: client *comment: | * the constructor for _client_ object @@ -14,6 +13,7 @@ var util = require("util"); var client = function(){ this.api_key = null; this.app_key = null; + this.proxy_agent = null; this.api_version = "v1"; this.api_host = "app.datadoghq.com"; }; @@ -69,9 +69,12 @@ client.prototype.request = function(method, path, params, callback){ hostname: this.api_host, port: 443, method: method.toUpperCase(), - path: path, + path: path }; + if(this.proxy_agent) + http_options["agent"] = this.proxy_agent; + if(["POST", "PUT"].indexOf(http_options["method"]) >= 0){ http_options["headers"] = { "Content-Type": "application/json", diff --git a/package.json b/package.json index f639aa1..55cec5c 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,8 @@ "dependencies": { "extend": "^2.0.0", "minimist": "^1.1.1", - "rc": "^1.0.0" + "rc": "^1.0.0", + "tls": "0.0.1" }, "devDependencies": { "docast": "^0.1.1",