From 3d3d6a16d908d8eab1d0104c7c07695c65bd37ab Mon Sep 17 00:00:00 2001 From: Christof Marti Date: Mon, 6 Jul 2026 09:14:31 +0200 Subject: [PATCH] Add HTTP proxy --- .../http-proxy-test/.vscode/tasks.json | 50 +++++++++++++++++++ .devcontainer/http-proxy-test/README.md | 16 ++++++ .../http-proxy-test/devcontainer-lock.json | 9 ++++ .../http-proxy-test/devcontainer.json | 10 ++++ .../http-proxy-test/docker-compose.yml | 23 +++++++++ .../http-proxy-test/http-proxy/Dockerfile | 4 ++ .../http-proxy-test/http-proxy/open.conf | 1 + .devcontainer/http-proxy-test/pac-server.js | 21 ++++++++ .devcontainer/http-proxy-test/package.json | 7 +++ .devcontainer/http-proxy-test/test.pac | 7 +++ 10 files changed, 148 insertions(+) create mode 100644 .devcontainer/http-proxy-test/.vscode/tasks.json create mode 100644 .devcontainer/http-proxy-test/README.md create mode 100644 .devcontainer/http-proxy-test/devcontainer-lock.json create mode 100644 .devcontainer/http-proxy-test/devcontainer.json create mode 100644 .devcontainer/http-proxy-test/docker-compose.yml create mode 100644 .devcontainer/http-proxy-test/http-proxy/Dockerfile create mode 100644 .devcontainer/http-proxy-test/http-proxy/open.conf create mode 100644 .devcontainer/http-proxy-test/pac-server.js create mode 100644 .devcontainer/http-proxy-test/package.json create mode 100644 .devcontainer/http-proxy-test/test.pac diff --git a/.devcontainer/http-proxy-test/.vscode/tasks.json b/.devcontainer/http-proxy-test/.vscode/tasks.json new file mode 100644 index 0000000..a4645e5 --- /dev/null +++ b/.devcontainer/http-proxy-test/.vscode/tasks.json @@ -0,0 +1,50 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "watch", + "dependsOn": [ + "npm: pac-server:run", + "npm: proxy-1:access-log", + "npm: proxy-2:access-log" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "runOptions": { + "runOn": "folderOpen" + } + }, + { + "type": "npm", + "script": "pac-server:run", + "group": "build", + "isBackground": true, + "label": "npm: pac-server:run", + "presentation": { + "group": "watch" + } + }, + { + "type": "npm", + "script": "proxy-1:access-log", + "group": "build", + "isBackground": true, + "label": "npm: proxy-1:access-log", + "presentation": { + "group": "watch" + } + }, + { + "type": "npm", + "script": "proxy-2:access-log", + "group": "build", + "isBackground": true, + "label": "npm: proxy-2:access-log", + "presentation": { + "group": "watch" + } + } + ] +} \ No newline at end of file diff --git a/.devcontainer/http-proxy-test/README.md b/.devcontainer/http-proxy-test/README.md new file mode 100644 index 0000000..7c8dd7d --- /dev/null +++ b/.devcontainer/http-proxy-test/README.md @@ -0,0 +1,16 @@ +## HTTP Proxy Test + +Use this dev container configuration with a different VS Code install than you want to test (e.g., use VS Code stable if you want to test VS Code Insiders). +- `Dev Containers: Reopen in Container` > `HTTP Proxy Test`. +- The dev container should show 3 log terminals: 1 for the proxy config (PAC), 2 for 2 proxies (no authentication). +- Locally start VS Code to test with the PAC file's URL, e.g.: `code-insiders --proxy-pac-url=http://localhost:4444`. + - Connections to *.github.com go through 127.0.0.1:3144. + - Connections to *.githubcopilot.com go through 127.0.0.1:3144. + - All other connections go through 127.0.0.1:3155. +- Install GitHub Copilot Chat and use `Developer: GitHub Copilot Chat Diagnostics` to test connections. +- Verify in the log terminals of the dev container that the PAC file and the proxies are being used. + +Optional (from other test passes): +- To further check extension support install https://marketplace.visualstudio.com/items?itemName=chrmarti.network-proxy-test. + - Update `test.pac` to apply the proxies to different domains, e.g., `https://example.com` and `https://marketplace.visualstudio.com`. + - Use `Network Proxy Test: Test Network Connection` to test. diff --git a/.devcontainer/http-proxy-test/devcontainer-lock.json b/.devcontainer/http-proxy-test/devcontainer-lock.json new file mode 100644 index 0000000..b0690d8 --- /dev/null +++ b/.devcontainer/http-proxy-test/devcontainer-lock.json @@ -0,0 +1,9 @@ +{ + "features": { + "ghcr.io/devcontainers/features/docker-outside-of-docker:1": { + "version": "1.5.0", + "resolved": "ghcr.io/devcontainers/features/docker-outside-of-docker@sha256:20761bd733511c1995ee955682cc2778b0a2e556abf88e9b88490c3be3c80bbc", + "integrity": "sha256:20761bd733511c1995ee955682cc2778b0a2e556abf88e9b88490c3be3c80bbc" + } + } +} \ No newline at end of file diff --git a/.devcontainer/http-proxy-test/devcontainer.json b/.devcontainer/http-proxy-test/devcontainer.json new file mode 100644 index 0000000..6eb9779 --- /dev/null +++ b/.devcontainer/http-proxy-test/devcontainer.json @@ -0,0 +1,10 @@ +{ + "name": "HTTP Proxy Test", + "dockerComposeFile": "docker-compose.yml", + "service": "devcontainer", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}/.devcontainer/http-proxy-test", + "features": { + "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {} + }, + "overrideCommand": true +} diff --git a/.devcontainer/http-proxy-test/docker-compose.yml b/.devcontainer/http-proxy-test/docker-compose.yml new file mode 100644 index 0000000..dd5e051 --- /dev/null +++ b/.devcontainer/http-proxy-test/docker-compose.yml @@ -0,0 +1,23 @@ +version: '3.4' + +services: + devcontainer: + image: mcr.microsoft.com/devcontainers/typescript-node:1-22-bookworm + volumes: + - ../../..:/workspaces + ports: + - "127.0.0.1:4444:4444" + http-proxy-1: + restart: always + build: + context: http-proxy + dockerfile: Dockerfile + ports: + - "127.0.0.1:3144:3128" + http-proxy-2: + restart: always + build: + context: http-proxy + dockerfile: Dockerfile + ports: + - "127.0.0.1:3155:3128" diff --git a/.devcontainer/http-proxy-test/http-proxy/Dockerfile b/.devcontainer/http-proxy-test/http-proxy/Dockerfile new file mode 100644 index 0000000..acaa8e2 --- /dev/null +++ b/.devcontainer/http-proxy-test/http-proxy/Dockerfile @@ -0,0 +1,4 @@ +FROM ubuntu/squid:latest + +COPY open.conf /etc/squid/conf.d/squid.acl.conf +RUN sed -e '/^http_access/ s/^#*/#/' -i /etc/squid/conf.d/debian.conf diff --git a/.devcontainer/http-proxy-test/http-proxy/open.conf b/.devcontainer/http-proxy-test/http-proxy/open.conf new file mode 100644 index 0000000..04c7e12 --- /dev/null +++ b/.devcontainer/http-proxy-test/http-proxy/open.conf @@ -0,0 +1 @@ +http_access allow all diff --git a/.devcontainer/http-proxy-test/pac-server.js b/.devcontainer/http-proxy-test/pac-server.js new file mode 100644 index 0000000..7f9aa0d --- /dev/null +++ b/.devcontainer/http-proxy-test/pac-server.js @@ -0,0 +1,21 @@ +const http = require('http'); +const fs = require('fs'); +const path = require('path'); + +const server = http.createServer((req, res) => { + console.log('Sending pac file...'); + const filePath = path.join(__dirname, 'test.pac'); + const stat = fs.statSync(filePath); + + res.writeHead(200, { + 'Content-Type': 'application/x-ns-proxy-autoconfig', + 'Content-Length': stat.size + }); + + const readStream = fs.createReadStream(filePath); + readStream.pipe(res); +}); + +server.listen(4444, () => { + console.log('Server is running on port 4444'); +}); \ No newline at end of file diff --git a/.devcontainer/http-proxy-test/package.json b/.devcontainer/http-proxy-test/package.json new file mode 100644 index 0000000..cc84455 --- /dev/null +++ b/.devcontainer/http-proxy-test/package.json @@ -0,0 +1,7 @@ +{ + "scripts": { + "pac-server:run": "node pac-server.js", + "proxy-1:access-log": "while true; do docker exec -it http-proxy-test-http-proxy-1-1 tail -F /var/log/squid/access.log ; sleep 1 ; done", + "proxy-2:access-log": "while true; do docker exec -it http-proxy-test-http-proxy-2-1 tail -F /var/log/squid/access.log ; sleep 1 ; done" + } +} diff --git a/.devcontainer/http-proxy-test/test.pac b/.devcontainer/http-proxy-test/test.pac new file mode 100644 index 0000000..6b4bfaa --- /dev/null +++ b/.devcontainer/http-proxy-test/test.pac @@ -0,0 +1,7 @@ +function FindProxyForURL(url, host) { + if (dnsDomainIs(host, "github.com")) + return "PROXY 127.0.0.1:3144"; + if (dnsDomainIs(host, "githubcopilot.com")) + return "PROXY 127.0.0.1:3144"; + return "PROXY 127.0.0.1:3155"; +} \ No newline at end of file