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.

HttpsProxyAgent.js.flow 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // @flow
  2. import net from 'net';
  3. import tls from 'tls';
  4. import type {
  5. ConnectionCallbackType,
  6. ConnectionConfigurationType,
  7. } from '../types';
  8. import Agent from './Agent';
  9. class HttpsProxyAgent extends Agent {
  10. // eslint-disable-next-line unicorn/prevent-abbreviations
  11. constructor (...args: *) {
  12. super(...args);
  13. this.protocol = 'https:';
  14. this.defaultPort = 443;
  15. }
  16. createConnection (configuration: ConnectionConfigurationType, callback: ConnectionCallbackType) {
  17. const socket = net.connect(
  18. configuration.proxy.port,
  19. configuration.proxy.hostname,
  20. );
  21. socket.on('error', (error) => {
  22. callback(error);
  23. });
  24. socket.once('data', () => {
  25. const secureSocket = tls.connect({
  26. ...configuration.tls,
  27. socket,
  28. });
  29. callback(null, secureSocket);
  30. });
  31. let connectMessage = '';
  32. connectMessage += 'CONNECT ' + configuration.host + ':' + configuration.port + ' HTTP/1.1\r\n';
  33. connectMessage += 'Host: ' + configuration.host + ':' + configuration.port + '\r\n';
  34. if (configuration.proxy.authorization) {
  35. connectMessage += 'Proxy-Authorization: Basic ' + Buffer.from(configuration.proxy.authorization).toString('base64') + '\r\n';
  36. }
  37. connectMessage += '\r\n';
  38. socket.write(connectMessage);
  39. }
  40. }
  41. export default HttpsProxyAgent;