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.

bindHttpMethod.js.flow 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // @flow
  2. import http from 'http';
  3. import https from 'https';
  4. type AgentType = http.Agent | https.Agent;
  5. // eslint-disable-next-line flowtype/no-weak-types
  6. export default (originalMethod: Function, agent: AgentType, forceGlobalAgent: boolean) => {
  7. // eslint-disable-next-line unicorn/prevent-abbreviations
  8. return (...args: *) => {
  9. let url;
  10. let options;
  11. let callback;
  12. if (typeof args[0] === 'string' || args[0] instanceof URL) {
  13. url = args[0];
  14. if (typeof args[1] === 'function') {
  15. options = {};
  16. callback = args[1];
  17. } else {
  18. options = {
  19. ...args[1],
  20. };
  21. callback = args[2];
  22. }
  23. } else {
  24. options = {
  25. ...args[0],
  26. };
  27. callback = args[1];
  28. }
  29. if (forceGlobalAgent) {
  30. options.agent = agent;
  31. } else {
  32. if (!options.agent) {
  33. options.agent = agent;
  34. }
  35. if (options.agent === http.globalAgent || options.agent === https.globalAgent) {
  36. options.agent = agent;
  37. }
  38. }
  39. if (url) {
  40. // $FlowFixMe
  41. return originalMethod(url, options, callback);
  42. } else {
  43. return originalMethod(options, callback);
  44. }
  45. };
  46. };