MCPcopy Create free account
hub / github.com/Azure/powershell / requestRawWithCallback

Method requestRawWithCallback

lib/index.js:2829–2875  ·  view source on GitHub ↗

* Raw request with callback. * @param info * @param data * @param onResult

(info, data, onResult)

Source from the content-addressed store, hash-verified

2827 * @param onResult
2828 */
2829 requestRawWithCallback(info, data, onResult) {
2830 if (typeof data === 'string') {
2831 if (!info.options.headers) {
2832 info.options.headers = {};
2833 }
2834 info.options.headers['Content-Length'] = Buffer.byteLength(data, 'utf8');
2835 }
2836 let callbackCalled = false;
2837 function handleResult(err, res) {
2838 if (!callbackCalled) {
2839 callbackCalled = true;
2840 onResult(err, res);
2841 }
2842 }
2843 const req = info.httpModule.request(info.options, (msg) => {
2844 const res = new HttpClientResponse(msg);
2845 handleResult(undefined, res);
2846 });
2847 let socket;
2848 req.on('socket', sock => {
2849 socket = sock;
2850 });
2851 // If we ever get disconnected, we want the socket to timeout eventually
2852 req.setTimeout(this._socketTimeout || 3 * 60000, () => {
2853 if (socket) {
2854 socket.end();
2855 }
2856 handleResult(new Error(`Request timeout: ${info.options.path}`));
2857 });
2858 req.on('error', function (err) {
2859 // err has statusCode property
2860 // res should have headers
2861 handleResult(err);
2862 });
2863 if (data && typeof data === 'string') {
2864 req.write(data, 'utf8');
2865 }
2866 if (data && typeof data !== 'string') {
2867 data.on('close', function () {
2868 req.end();
2869 });
2870 data.pipe(req);
2871 }
2872 else {
2873 req.end();
2874 }
2875 }
2876 /**
2877 * Gets an http agent. This function is useful when you need an http agent that handles
2878 * routing through a proxy server - depending upon the url and proxy environment variables.

Callers 1

requestRawMethod · 0.95

Calls 2

requestMethod · 0.80
writeMethod · 0.80

Tested by

no test coverage detected