(uri, options)
| 845 | } |
| 846 | |
| 847 | function request_call(uri, options) { |
| 848 | |
| 849 | var opt; |
| 850 | |
| 851 | if (options.proxy && !options.proxy.tls) { |
| 852 | opt = PROXYOPTIONSHTTP; |
| 853 | opt.port = options.proxy.port; |
| 854 | opt.host = options.proxy.hostname; |
| 855 | opt.path = uri.href; |
| 856 | opt.headers = uri.headers; |
| 857 | opt.method = uri.method; |
| 858 | opt.headers.host = uri.host; |
| 859 | if (options.proxy._auth) |
| 860 | opt.headers['Proxy-Authorization'] = options.proxy._auth; |
| 861 | } else |
| 862 | opt = uri; |
| 863 | |
| 864 | var connection = uri.protocol === 'https:' ? Https : Http; |
| 865 | var req = options.post ? connection.request(opt, request_response) : connection.get(opt, request_response); |
| 866 | |
| 867 | req.$options = options; |
| 868 | req.$uri = uri; |
| 869 | |
| 870 | if (!options.callback) { |
| 871 | req.on('error', NOOP); |
| 872 | return; |
| 873 | } |
| 874 | |
| 875 | req.on('error', request_process_error); |
| 876 | options.timeoutid && clearTimeout(options.timeoutid); |
| 877 | options.timeoutid = setTimeout(request_process_timeout, options.timeout, req); |
| 878 | |
| 879 | // req.on('response', (response) => response.req = req); |
| 880 | req.on('response', request_assign_res); |
| 881 | |
| 882 | if (options.upload) { |
| 883 | options.first = true; |
| 884 | options.files.wait(function(file, next) { |
| 885 | request_writefile(req, options, file, next); |
| 886 | }, function() { |
| 887 | var keys = Object.keys(options.data); |
| 888 | for (var i = 0, length = keys.length; i < length; i++) { |
| 889 | var value = options.data[keys[i]]; |
| 890 | if (value != null) { |
| 891 | req.write((options.first ? '' : NEWLINE) + '--' + options.boundary + NEWLINE + 'Content-Disposition: form-data; name="' + keys[i] + '"' + NEWLINE + NEWLINE + value.toString()); |
| 892 | if (options.first) |
| 893 | options.first = false; |
| 894 | } |
| 895 | } |
| 896 | req.end(NEWLINE + '--' + options.boundary + '--'); |
| 897 | }); |
| 898 | } else |
| 899 | req.end(options.data); |
| 900 | } |
| 901 | |
| 902 | function request_process_error(err) { |
| 903 | var options = this.$options; |
no test coverage detected