Giter Club home page Giter Club logo

pinf-proxy-js's Introduction

pinf

Status: DEV

The pinf command implementation used for hoisting PINF-based programs. NodeJS is used as the runtime engine for pinf.

What is PINF?

PINF is a set of specific tools and conventions combined to create a platform that allows for the creation of portable programs implemented by orchestrating diverse packages and services contributed and operated by a distributed community. The pinf command is an application used to call PINF-based programs.

PINF enables collaboratively built systems of arbitrary complexity.

Setup

Requirements:

  • OSX >= 10.8
  • NodeJS >= 0.10
  • git >= 1.8

Install:

sudo npm install -g pinf --tag pre

Test:

npm install
export DEBUG=debug  # Optionally enable debug logging
export TEST=02      # Run only the matching (prefix) test group
npm test

Usage

Calling local PINF Programs (see: 01-SimpleCommandLinePiping):

# Output Redirection
$ pinf say 'Fred:' > fred.txt && pinf color 36 < fred.txt | pinf append ' hello'
> Fred: hello

# Streaming
$ pinf send 3 Hello | pinf color 36 | pinf collect
> collected: Hello
> collected: Hello
> collected: Hello

Calling cloned PINF Programs (see: 02-SimpleProvisionFromGithub):

# Clone once and use cached tag on every subsequent run
$ pinf github.com/pinf/pinf/v1.0.0-pre.3?test/01-SimpleCommandLinePiping/programs/say Hello
> Hello

# Clone once and fetch from branch on every subsequent run
$ pinf github.com/pinf/pinf/master?test/01-SimpleCommandLinePiping/programs/say Hello
> Hello

# Automatically buffer streams while provisioning programs
$ pinf github.com/pinf/pinf/v1.0.0-pre.3?test/01-SimpleCommandLinePiping/programs/send 3 Hello \
$ | pinf github.com/pinf/pinf/v1.0.0-pre.4?test/01-SimpleCommandLinePiping/programs/color 36 \
$ | pinf github.com/pinf/pinf/v1.0.0-pre.3?test/01-SimpleCommandLinePiping/programs/collect
> collected: Hello
> collected: Hello
> collected: Hello

TODO

Integrate

pinf-proxy-js's People

Contributors

cadorn avatar

Watchers

 avatar  avatar

pinf-proxy-js's Issues

SSL tunnel through HTTP[S]_PROXY

These tests

  • pinf-proxy-js/test/proxy.js

    Lines 156 to 174 in 81cafdc

    // TODO: Fix.
    /*
    it("can proxy HTTPS requests", function(done) {
    return PROXY.newProxy({
    enableForwardHeaders: true
    }, function(err, proxy) {
    if (err) return done(err);
    return REQUEST(proxy.useForRequest("https://www.microsoft.com/robots.txt"), function(err, res, body) {
    if (err) return done(err);
    ASSERT.equal(res.statusCode, 200);
    //console.log("body", body);
    ASSERT.equal(/# Robots\.txt file for/.test(body), true);
    return proxy.close(done);
    });
    });
    });
    */
  • pinf-proxy-js/test/proxy.js

    Lines 205 to 236 in 81cafdc

    // TODO: Fix.
    /*
    it("can proxy sub-commands via `HTTP_PROXY` ENV var", function(done) {
    return PROXY.newProxy({
    enableForwardHeaders: true
    }, function(err, proxy) {
    if (err) return done(err);
    var proc = SPAWN("curl", [
    "-s",
    "-v",
    "https://www.microsoft.com/robots.txt"
    ], {
    env: proxy.useForEnv(process.env)
    });
    var ok = false;
    proc.stdout.on('data', function (data) {
    console.log('stdout: ' + data);
    if (/# Robots\.txt file for/.test(data)) {
    ok = true;
    }
    });
    proc.stderr.on('data', function (data) {
    console.log('stderr: ' + data);
    });
    proc.on('close', function (code) {
    if (code) return done(new Error("Did not exit clean!"));
    if (!ok) ASSERT.fail("Not not get expected response");
    return proxy.close(done);
    });
    });
    });
    */

make HTTPS requests via request and curl with proxy property and HTTPS_PROXY env var set respectively.

Both connect to

pinf-proxy-js/lib/proxy.js

Lines 136 to 204 in 81cafdc

// NOTE: A SSL proxy cannot inspect traffic passing through it!
// @see http://tools.ietf.org/html/draft-luotonen-ssl-tunneling-03
// TODO: Get this working when making HTTPS requests using `request` and `curl`.
// `request` wants to connect via TLS while `curl` want to connect via NET.
self._server = NET.createServer({
key: options.https.key,
cert: options.https.cert,
rejectUnauthorized: false
}, function(requestingStream) {
requestingStream.end();
/*
var targetStream = null;
requestingStream.on("data", function(chunk) {
//console.log(" >> CHUNK >> ", chunk.toString());
if (targetStream) {
targetStream.write(chunk);
} else {
// Expecting:
// CONNECT www.test.com:443 HTTP/1.1
// Host: www.test.com:443
// Connection: close
var headers = {};
chunk.toString().replace(/\r/g, "").split("\n").forEach(function(line) {
var m = line.match(/^([^:]+):\s*(.*)$/);
if (m) {
headers[m[1]] = m[2];
}
});
if (!headers["Host"]) {
return requestingStream.end();
}
var hostnamePort = headers["Host"].split(":");
if (hostnamePort[1] != 443) {
return requestingStream.end();
}
targetStream = require("net").connect({
host: hostnamePort[0],
port: 443
}, function() {
requestingStream.write("HTTP/1.0 200 Connection established\n\n");
});
targetStream.on("error", function(err) {
console.error(err.stack);
requestingStream.close();
});
targetStream.on("close", function() {
requestingStream.close();
});
targetStream.on("data", function(chunk) {
//console.log(" << CHUNK << ", chunk.toString());
requestingStream.write(chunk);
});
requestingStream.once("close", function() {
targetStream.close();
});
}
});
*/
});

One wants to connect over a TLS connection the other just plain NET.

Both send the CONNECT header but relaying data does not seem to work.

Also see: http://stackoverflow.com/questions/10876883/implementing-an-http-proxy

The goal is to have pinf-proxy-js be able to proxy all requests generated by attaching to request, http, https in nodejs and declaring HTTP[S]_PROXY in shell environment variables.

$limitation The impact of this bug on the pinf ecosystem is that assets fetched over HTTP and HTTPS cannot be sniffed for shell environments (as declaring HTTP_PROXY will also cause HTTPS requests to go through it) and for HTTPS requests using request with proxy set.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.