Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

agents.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* jshint node:true */
  2. 'use strict';
  3. var util = require('util');
  4. var http = require('http');
  5. var HttpAgent = http.Agent;
  6. var https = require('https');
  7. var HttpsAgent = https.Agent;
  8. var pick = require('lodash/pick');
  9. /**
  10. * Proxy some traffic over HTTP.
  11. */
  12. function OuterHttpAgent(opts) {
  13. HttpAgent.call(this, opts);
  14. mixinProxying(this, opts.proxy);
  15. }
  16. util.inherits(OuterHttpAgent, HttpAgent);
  17. exports.OuterHttpAgent = OuterHttpAgent;
  18. /**
  19. * Proxy some traffic over HTTPS.
  20. */
  21. function OuterHttpsAgent(opts) {
  22. HttpsAgent.call(this, opts);
  23. mixinProxying(this, opts.proxy);
  24. }
  25. util.inherits(OuterHttpsAgent, HttpsAgent);
  26. exports.OuterHttpsAgent = OuterHttpsAgent;
  27. /**
  28. * Override createConnection and addRequest methods on the supplied agent.
  29. * http.Agent and https.Agent will set up createConnection in the constructor.
  30. */
  31. function mixinProxying(agent, proxyOpts) {
  32. agent.proxy = proxyOpts;
  33. var orig = pick(agent, 'createConnection', 'addRequest');
  34. // Make the tcp or tls connection go to the proxy, ignoring the
  35. // destination host:port arguments.
  36. agent.createConnection = function(port, host, options) {
  37. return orig.createConnection.call(this, this.proxy.port, this.proxy.host, options);
  38. };
  39. agent.addRequest = function(req, options) {
  40. req.path =
  41. this.proxy.innerProtocol + '//' + options.host + ':' + options.port + req.path;
  42. return orig.addRequest.call(this, req, options);
  43. };
  44. }