MCPcopy Index your code
hub / github.com/totaljs/framework / request_call

Function request_call

utils.js:847–900  ·  view source on GitHub ↗
(uri, options)

Source from the content-addressed store, hash-verified

845}
846
847function 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
902function request_process_error(err) {
903 var options = this.$options;

Callers 3

utils.jsFile · 0.85
request_resolveFunction · 0.85
request_responseFunction · 0.85

Calls 1

request_writefileFunction · 0.85

Tested by

no test coverage detected