@simonyea/holysheep-cli 2.1.21 → 2.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simonyea/holysheep-cli",
3
- "version": "2.1.21",
3
+ "version": "2.1.22",
4
4
  "description": "Claude Code/Cursor/Cline API relay for China \u2014 \u00a51=$1, WeChat/Alipay payment, no credit card, no VPN. One command setup for all AI coding tools.",
5
5
  "scripts": {
6
6
  "test": "node tests/droid.test.js && node tests/workspace-store.test.js && node tests/runtime-stale-upgrade.test.js && node tests/hermes.test.js && node tests/preflight.test.js",
@@ -324,6 +324,26 @@ function forwardViaNodeProxy({ nodeProxyUrl, targetUrl, clientReq, clientRes, ex
324
324
  host: targetUrl.host,
325
325
  connection: 'close',
326
326
  }
327
+ // Build the forward-proxy path. CRS's per-node proxy at :3129 accepts an
328
+ // absolute URL as the HTTP/1.1 request target and rewrites the scheme
329
+ // internally. We ALWAYS send http:// in the path (even if targetUrl is
330
+ // https://) because:
331
+ // 1. node:3129 listens on plain HTTP and ignores the scheme of the
332
+ // request-target — it reads `targetUrl = new URL(req.url)`,
333
+ // validates hostname, and proxies upstream.
334
+ // 2. bun's `http.request` treats `path: 'https://...'` as a signal to
335
+ // issue a CONNECT tunnel (instead of a plain absolute-URI forward
336
+ // request), which silently drops the x-hs-* headers we injected
337
+ // because they would only ride on the outer CONNECT, not the inner
338
+ // TLS tunnel — yielding 403 'Missing bridge session headers'.
339
+ // (Node's `http.request` does NOT have this behaviour; the bug is
340
+ // bun-specific. Reproduced under bun 1.3.9 at AionUi's runtime.)
341
+ // Rewriting to http:// preserves correctness on both runtimes.
342
+ const forwardPath = (() => {
343
+ const clone = new URL(targetUrl.toString())
344
+ clone.protocol = 'http:'
345
+ return clone.toString()
346
+ })()
327
347
  if (ENABLE_TIMING_LOG) {
328
348
  const hsHeaders = Object.fromEntries(
329
349
  Object.entries(finalHeaders).filter(([k]) => /^x-hs-/i.test(k))
@@ -331,6 +351,7 @@ function forwardViaNodeProxy({ nodeProxyUrl, targetUrl, clientReq, clientRes, ex
331
351
  console.error(
332
352
  `[hs-claude-proxy] forward.headers ${JSON.stringify({
333
353
  target: sanitizeUrl(targetUrl),
354
+ forwardPath,
334
355
  node: sanitizeUrl(nodeProxyUrl),
335
356
  hsHeaders,
336
357
  clientHeadersKeys: Object.keys(clientReq.headers).slice(0, 20),
@@ -341,7 +362,7 @@ function forwardViaNodeProxy({ nodeProxyUrl, targetUrl, clientReq, clientRes, ex
341
362
  host: upstream.hostname,
342
363
  port: Number(upstream.port || 80),
343
364
  method: clientReq.method,
344
- path: targetUrl.toString(),
365
+ path: forwardPath,
345
366
  agent: false,
346
367
  headers: finalHeaders,
347
368
  }, (forwardRes) => {
@@ -505,6 +526,17 @@ function pipeWithCleanup(a, b) {
505
526
  function createProcessProxyServer({ sessionId, configPath = CONFIG_PATH, allowAnthropicConnect = false }) {
506
527
  const server = http.createServer(async (clientReq, clientRes) => {
507
528
  const isDirect = !clientReq.url.startsWith('http')
529
+ if (ENABLE_TIMING_LOG) {
530
+ console.error(
531
+ `[hs-claude-proxy] incoming ${JSON.stringify({
532
+ method: clientReq.method,
533
+ url: String(clientReq.url).slice(0, 120),
534
+ ua: String(clientReq.headers['user-agent'] || '').slice(0, 60),
535
+ host: clientReq.headers.host || '',
536
+ isDirect,
537
+ })}`
538
+ )
539
+ }
508
540
 
509
541
  const doForward = async (lease, attempt) => {
510
542
  const config = readConfig(configPath)
@@ -602,6 +634,15 @@ function createProcessProxyServer({ sessionId, configPath = CONFIG_PATH, allowAn
602
634
 
603
635
  server.on('connect', async (req, clientSocket, head) => {
604
636
  const target = String(req.url || '').trim()
637
+ if (ENABLE_TIMING_LOG) {
638
+ console.error(
639
+ `[hs-claude-proxy] incoming.CONNECT ${JSON.stringify({
640
+ target: target.slice(0, 120),
641
+ ua: String(req.headers['user-agent'] || '').slice(0, 60),
642
+ headers: Object.keys(req.headers).slice(0, 20),
643
+ })}`
644
+ )
645
+ }
605
646
  const [host, rawPort] = target.split(':')
606
647
  const port = Number(rawPort || 443)
607
648
  if (!host || !Number.isInteger(port) || ![80, 443].includes(port)) {