From aa59a979fd44fb6d3036150e386099470e576323 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 24 Aug 2017 17:50:36 +0200 Subject: Add proxy module --- modules/proxy/.gitignore | 1 + modules/proxy/proxy.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 modules/proxy/.gitignore create mode 100644 modules/proxy/proxy.js (limited to 'modules') diff --git a/modules/proxy/.gitignore b/modules/proxy/.gitignore new file mode 100644 index 0000000..f4a3cc2 --- /dev/null +++ b/modules/proxy/.gitignore @@ -0,0 +1 @@ +idfile.txt diff --git a/modules/proxy/proxy.js b/modules/proxy/proxy.js new file mode 100644 index 0000000..66c50df --- /dev/null +++ b/modules/proxy/proxy.js @@ -0,0 +1,50 @@ +var cmn=require("../$common.js"), + fs=require("fs"), + http=require("http"), + https=require("https"), + URL=require("url"); + + +function fetch(method,url,cb){ + var module; + if(url.slice(0,7)=="http://")module=http; + else if(url.slice(0,8)=="https://")module=https; + var obj=URL.parse(url); + obj.method=method; + module.request(obj,function(res){ + var body=""; + res.on("data",function(data){body+=data;}); + res.on("end",function(){ + cb(res.statusCode,body); + }); + }).on("error",function(){ + cb(null,null); + }).end(); +} + +function objectFromList(l){ + var obj={}; + for(var i=0;i