租房小程序前端代码
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.

82 lines
1.9 KiB

6 months ago
  1. //"version": "2.8.2",
  2. var ClientRequest = require('./lib/request');
  3. var response = require('./lib/response');
  4. var extend = require('xtend');
  5. var statusCodes = require('builtin-status-codes');
  6. var url = require('url');
  7. var http = exports;
  8. http.request = function (opts, cb) {
  9. if (typeof opts === 'string') opts = url.parse(opts);
  10. else opts = extend(opts);
  11. // Normally, the page is loaded from http or https, so not specifying a protocol
  12. // will result in a (valid) protocol-relative url. However, this won't work if
  13. // the protocol is something else, like 'file:'
  14. var defaultProtocol = global.location.protocol.search(/^https?:$/) === -1 ? 'http:' : '';
  15. var protocol = opts.protocol || defaultProtocol;
  16. var host = opts.hostname || opts.host;
  17. var port = opts.port;
  18. var path = opts.path || '/';
  19. // Necessary for IPv6 addresses
  20. if (host && host.indexOf(':') !== -1) host = '[' + host + ']';
  21. // This may be a relative url. The browser should always be able to interpret it correctly.
  22. opts.url = (host ? protocol + '//' + host : '') + (port ? ':' + port : '') + path;
  23. opts.method = (opts.method || 'GET').toUpperCase();
  24. opts.headers = opts.headers || {};
  25. // Also valid opts.auth, opts.mode
  26. var req = new ClientRequest(opts);
  27. if (cb) req.on('response', cb);
  28. return req;
  29. };
  30. http.get = function get(opts, cb) {
  31. var req = http.request(opts, cb);
  32. req.end();
  33. return req;
  34. };
  35. http.ClientRequest = ClientRequest;
  36. http.IncomingMessage = response.IncomingMessage;
  37. http.Agent = function () {};
  38. http.Agent.defaultMaxSockets = 4;
  39. http.globalAgent = new http.Agent();
  40. http.STATUS_CODES = statusCodes;
  41. http.METHODS = [
  42. 'CHECKOUT',
  43. 'CONNECT',
  44. 'COPY',
  45. 'DELETE',
  46. 'GET',
  47. 'HEAD',
  48. 'LOCK',
  49. 'M-SEARCH',
  50. 'MERGE',
  51. 'MKACTIVITY',
  52. 'MKCOL',
  53. 'MOVE',
  54. 'NOTIFY',
  55. 'OPTIONS',
  56. 'PATCH',
  57. 'POST',
  58. 'PROPFIND',
  59. 'PROPPATCH',
  60. 'PURGE',
  61. 'PUT',
  62. 'REPORT',
  63. 'SEARCH',
  64. 'SUBSCRIBE',
  65. 'TRACE',
  66. 'UNLOCK',
  67. 'UNSUBSCRIBE'
  68. ];