Skip to content

Commit

Permalink
Configure proxy-agent (microsoft/vscode-remote-release#6995)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Oct 11, 2022
1 parent 5dc27b9 commit 8a91fc1
Show file tree
Hide file tree
Showing 4 changed files with 317 additions and 52 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"jsonc-parser": "^3.0.0",
"ncp": "^2.0.0",
"node-pty": "^0.10.1",
"proxy-agent": "^5.0.0",
"pull-stream": "^3.6.14",
"recursive-readdir": "^2.2.2",
"semver": "^7.3.5",
Expand Down
11 changes: 8 additions & 3 deletions src/spec-utils/httpRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import type { RequestOptions } from 'https';
import { https } from 'follow-redirects';
import ProxyAgent from 'proxy-agent';
import * as url from 'url';
import { Log, LogLevel } from './log';

export function request(options: { type: string; url: string; headers: Record<string, string>; data?: Buffer }, output?: Log) {
return new Promise<Buffer>((resolve, reject) => {
const parsed = new url.URL(options.url);
const reqOptions = {
const reqOptions: RequestOptions = {
hostname: parsed.hostname,
port: parsed.port,
path: parsed.pathname + parsed.search,
method: options.type,
headers: options.headers,
agent: new ProxyAgent(),
};
const req = https.request(reqOptions, res => {
if (res.statusCode! < 200 || res.statusCode! > 299) {
Expand All @@ -42,12 +45,13 @@ export function request(options: { type: string; url: string; headers: Record<st
export function headRequest(options: { url: string; headers: Record<string, string> }, output?: Log) {
return new Promise<number>((resolve, reject) => {
const parsed = new url.URL(options.url);
const reqOptions = {
const reqOptions: RequestOptions = {
hostname: parsed.hostname,
port: parsed.port,
path: parsed.pathname + parsed.search,
method: 'HEAD',
headers: options.headers,
agent: new ProxyAgent(),
};
const req = https.request(reqOptions, res => {
res.on('error', reject);
Expand All @@ -65,12 +69,13 @@ export function headRequest(options: { url: string; headers: Record<string, stri
export function requestResolveHeaders(options: { type: string; url: string; headers: Record<string, string>; data?: Buffer }, _output?: Log) {
return new Promise<{ statusCode: number; resHeaders: Record<string, string> }>((resolve, reject) => {
const parsed = new url.URL(options.url);
const reqOptions = {
const reqOptions: RequestOptions = {
hostname: parsed.hostname,
port: parsed.port,
path: parsed.pathname + parsed.search,
method: options.type,
headers: options.headers,
agent: new ProxyAgent(),
};
const req = https.request(reqOptions, res => {
res.on('error', reject);
Expand Down
43 changes: 0 additions & 43 deletions src/spec-utils/net.ts

This file was deleted.

Loading

0 comments on commit 8a91fc1

Please sign in to comment.