CodeSampleX

サンプル

proxy-from-env 2.1.0: getProxyForUrl

検証済みサンプル — npm proxy-from-env 2.1.0: getProxyForUrl. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: getProxyForUrl returns an empty string when…

sha256:3556451b175837841c95be340422e5436b1fc5329b6300af9d31d9268041c8a3

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

検証実行環境

環境 コントラクト ステージ 実行日
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-04

ケース

HOW
ゴール
verify proxy-from-env.getProxyForUrl in pkg:npm/proxy-from-env@2.1.0
パッケージ
シンボル
  • proxy-from-env.getProxyForUrl
環境
node 22.23.2
作成日
2026-09-04T05:23:52Z

コントラクト

  1. getProxyForUrl returns an empty string when no proxy environment variables are set
  2. getProxyForUrl returns HTTP_PROXY for http URLs and HTTPS_PROXY for https URLs
  3. getProxyForUrl falls back to ALL_PROXY when protocol-specific proxy is unset
  4. getProxyForUrl returns an empty string when NO_PROXY is wildcard asterisk
  5. getProxyForUrl respects NO_PROXY for exact hostnames and domain suffixes
  6. getProxyForUrl respects port-specific NO_PROXY rules
  7. getProxyForUrl prepends the request protocol scheme when the proxy environment variable lacks a URL scheme
  8. getProxyForUrl accepts URL object instances as input
  9. getProxyForUrl returns an empty string when given an invalid URL or string without a valid hostname

ファイル

  • .npmrc
  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

ソースアーティファクトをダウンロード (tar.gz)

ソース

.npmrc
audit=false
fund=false
PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify proxy-from-env.getProxyForUrl in pkg:npm/proxy-from-env@2.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/proxy-from-env@2.1.0
Demonstrate these symbols/APIs:
  - proxy-from-env.getProxyForUrl
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:3a13665158a48056ab5fb4f19f7564042c8659fcfbc74ffb32b3bfdf20b8fb95","constraints":{"executionContext":"node"},"contract":["getProxyForUrl returns an empty string when no proxy environment variables are set","getProxyForUrl returns HTTP_PROXY for http URLs and HTTPS_PROXY for https URLs","getProxyForUrl falls back to ALL_PROXY when protocol-specific proxy is unset","getProxyForUrl returns an empty string when NO_PROXY is wildcard asterisk","getProxyForUrl respects NO_PROXY for exact hostnames and domain suffixes","getProxyForUrl respects port-specific NO_PROXY rules","getProxyForUrl prepends the request protocol scheme when the proxy environment variable lacks a URL scheme","getProxyForUrl accepts URL object instances as input","getProxyForUrl returns an empty string when given an invalid URL or string without a valid hostname"],"goal":"verify proxy-from-env.getProxyForUrl in pkg:npm/proxy-from-env@2.1.0","kind":"HOW","packages":["pkg:npm/proxy-from-env@2.1.0"],"schemaVersion":1,"symbols":["proxy-from-env.getProxyForUrl"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/proxy-from-env@2.1.0"],"schemaVersion":1,"subject":"pkg:npm/proxy-from-env@2.1.0","symbols":["proxy-from-env.getProxyForUrl"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-proxy-from-env",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-proxy-from-env",
      "version": "1.0.0",
      "dependencies": {
        "proxy-from-env": "2.1.0"
      }
    },
    "node_modules/proxy-from-env": {
      "version": "2.1.0",
      "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-2.1.0.tgz",
      "integrity": "sha512-cJ+oHTW1VAEa8cJslgmUZrc+sjRKgAKl3Zyse6+PV38hZe/V6Z14TbCuXcan9F9ghlz4QrFr2c92TNF82UkYHA==",
      "license": "MIT",
      "engines": {
        "node": ">=10"
      }
    }
  }
}
package.json
{
  "name": "sample-proxy-from-env",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "proxy-from-env": "2.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify proxy-from-env.getProxyForUrl in pkg:npm/proxy-from-env@2.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/proxy-from-env@2.1.0"
  ],
  "symbols": [
    "proxy-from-env.getProxyForUrl"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import process from 'node:process';
import { getProxyForUrl } from 'proxy-from-env';

function clearProxyEnv() {
	delete process.env.http_proxy;
	delete process.env.HTTP_PROXY;
	delete process.env.https_proxy;
	delete process.env.HTTPS_PROXY;
	delete process.env.all_proxy;
	delete process.env.ALL_PROXY;
	delete process.env.no_proxy;
	delete process.env.NO_PROXY;
}

// 1. getProxyForUrl returns an empty string when no proxy environment variables are set
{
	clearProxyEnv();
	const proxy = getProxyForUrl('http://example.com/test');
	assert.equal(proxy, '');
}

// 2. getProxyForUrl returns HTTP_PROXY for http URLs and HTTPS_PROXY for https URLs
{
	clearProxyEnv();
	process.env.HTTP_PROXY = 'http://proxy.example.com:8080';
	process.env.HTTPS_PROXY = 'http://secure-proxy.example.com:8443';
	assert.equal(getProxyForUrl('http://example.com/api'), 'http://proxy.example.com:8080');
	assert.equal(getProxyForUrl('https://example.com/api'), 'http://secure-proxy.example.com:8443');
}

// 3. getProxyForUrl falls back to ALL_PROXY when protocol-specific proxy is unset
{
	clearProxyEnv();
	process.env.ALL_PROXY = 'socks5://all-proxy.example.com:1080';
	assert.equal(getProxyForUrl('http://example.com/data'), 'socks5://all-proxy.example.com:1080');
	assert.equal(getProxyForUrl('https://example.com/data'), 'socks5://all-proxy.example.com:1080');
}

// 4. getProxyForUrl returns an empty string when NO_PROXY is wildcard asterisk
{
	clearProxyEnv();
	process.env.HTTP_PROXY = 'http://proxy.example.com:8080';
	process.env.NO_PROXY = '*';
	assert.equal(getProxyForUrl('http://example.com/test'), '');
	assert.equal(getProxyForUrl('http://other.example.com/test'), '');
}

// 5. getProxyForUrl respects NO_PROXY for exact hostnames and domain suffixes
{
	clearProxyEnv();
	process.env.HTTP_PROXY = 'http://proxy.example.com:8080';
	process.env.NO_PROXY = 'sub.example.com,.corp.example.com';
	assert.equal(getProxyForUrl('http://sub.example.com/index'), '');
	assert.equal(getProxyForUrl('http://app.corp.example.com/'), '');
	assert.equal(getProxyForUrl('http://other.example.com/'), 'http://proxy.example.com:8080');
}

// 6. getProxyForUrl respects port-specific NO_PROXY rules
{
	clearProxyEnv();
	process.env.HTTP_PROXY = 'http://proxy.example.com:8080';
	process.env.NO_PROXY = 'example.com:8080';
	assert.equal(getProxyForUrl('http://example.com:8080/test'), '');
	assert.equal(getProxyForUrl('http://example.com:3000/test'), 'http://proxy.example.com:8080');
}

// 7. getProxyForUrl prepends the request protocol scheme when the proxy environment variable lacks a URL scheme
{
	clearProxyEnv();
	process.env.HTTP_PROXY = '127.0.0.1:8080';
	const proxy = getProxyForUrl('http://example.com/data');
	assert.equal(proxy, 'http://127.0.0.1:8080');
}

// 8. getProxyForUrl accepts URL object instances as input
{
	clearProxyEnv();
	process.env.HTTP_PROXY = 'http://proxy.example.com:8080';
	const urlObj = new URL('http://example.com/object-test');
	assert.equal(getProxyForUrl(urlObj), 'http://proxy.example.com:8080');
}

// 9. getProxyForUrl returns an empty string when given an invalid URL or string without a valid hostname
{
	clearProxyEnv();
	process.env.HTTP_PROXY = 'http://proxy.example.com:8080';
	assert.equal(getProxyForUrl('not-a-valid-url'), '');
	assert.equal(getProxyForUrl(''), '');
}

オリジンシーダー

匿名