Skip to content

Instantly share code, notes, and snippets.

@mauritslamers
Created February 2, 2018 16:18
Show Gist options
  • Save mauritslamers/a60710e7db5c39ffbb0cb061adc0354f to your computer and use it in GitHub Desktop.
Save mauritslamers/a60710e7db5c39ffbb0cb061adc0354f to your computer and use it in GitHub Desktop.
var proxyToelating = function (origReq, origResp, next) {
var url = origReq.url;
var path = require('url').parse(url).pathname;
var proxyReq;
console.log("Trying to proxying " + url);
var me = this;
if (origReq.headers.host) origReq.headers.host = "";
origReq.headers['Authorization'] = "Basic myauth=";
proxyReq = require('https').request({
hostname: "my.host.ext",
path: path,
method: origReq.method,
headers: origReq.headers,
agent: false
},
function (proxyres) {
console.log(proxyres);
proxyres.pipe(origResp, { end: true });
}
);
origReq.pipe(proxyReq, { end : true });
}
/// further on
app.use('/webdav', proxyToelating);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment