From 45b49b72a181f8f341513ca0f66957a4cc61227a Mon Sep 17 00:00:00 2001 From: Jason Caldwell Date: Sat, 17 Feb 2024 06:33:50 -0500 Subject: [PATCH] Project update. [p][robotic] --- .env.vault | 8 ++++---- package.json | 2 +- src/proxy.ts | 12 +++++++----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.env.vault b/.env.vault index 109de8a..c47b595 100644 --- a/.env.vault +++ b/.env.vault @@ -8,12 +8,12 @@ DOTENV_VAULT_MAIN="3rfi+ClkONvfHPiU9FTBcC1+Um/L8QeM9dRw1jFzEqzZXw==" DOTENV_VAULT_MAIN_VERSION=1 # dev -DOTENV_VAULT_DEV="AH3nYu+BcvndByTWLaNET0EfxdqcjS2T2hyIR3B2FxmWmC5zbk2fyYK1Ag2PcZunmDS2eRlHrWDsWQEiD8Rc8LQor5r9kA4wVLW1V8NWKdZ+8CX3gd2lAqPNeCo8tpun0ayCl2VKTZ0eUJBGTroSSAAJglE/Ashvc6DwK1J8zkW1InvCccVgi5QWqGdd9ZyGHoMz2nGlhANElip2TqWmJgvdF69r3XCESFqlsL/kuuFYMFxWtnCNtojcpSjrrKF6gTUrTNf4x3pQ4J9cSCc4NF0dIrVpPLBj/MFjMy1etHjimGLnRqLiwJ1jwKCT44oGP7JzwNisYj+skqPT4z6qhEegPBIPYL9NEpcG5Lcul4fUUEVXYge9qjTYRCjTrIry1zjLRV8qbe0GRTWai8aNmSMftO8VY+NZuv0JESOy6YmBlZlsDtMIGBHcKb+8YKhr7czk6BbIAoMsne1M93jNUR4bcZJhiJwhFrOtPKYlNzDb+xd3aCQMkkDtLklo5ym45NTE4w1ATQ8eZcisLjDUaK1+7yWt9xWLi5Dd24LOTM83iqmnEb143f0xKuHBPKdwfQg3Db7vQ3Fe9QGi5YEDCJLF3rwjvW7o/Zmu1h5jzqSKiFPAlZj0GkGO/+qI5wX6kUwrsSiLW9yw0xPRBmbJ1i9U5wmPuQ6isUqzN+xhsQkimH3RhNs6cwPSe0/3RTLCg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ArG4B56Ay0NvscrRu+zKuafQaiUXDtsGVQKLGqsSUM8AL7aRfrW6T7fg/crKYzyMXDwnq7rJWPFFcIIB0dgOO0ikw50GKe5yfmi2H78wS1nh9iYeQWsWOFSe6KeVoGw0qOSndnr3i1bH13UOZb7PVVfvCYF3bOVELSoqgfOGLTUJvoC/7WQQ7CBzeW8C5zxLDoj9Tw084OyQa4r4psBUs70v7N7oo5AS8UBx9dH0at57P0a6u5iCOXlW0QAtzjO7m+VgfEmwsTKy3+QuZy585eI30wBp+3/X/zEJBzKOmmQI6vxSW5uK9EnMlY/jQIXk0MaOuKBBnwofuTOuigmR5vxdXgc5oqhUlRX0dMRWhcQKQ5mrrxOpT01gJuEkmB779MWlmOIcKUHdeAreQguEhjVtTyJwuhEeietJ+THv3uJjLewvcFrvaV3FiWQ7pWE9siNwHyzrTFAC3SxVBpXLcduj68gVwW95oA52WIwO00XmCLq9xZ5xwN5vxZM+1GZdg2KPsqIfLoMaXkxbKCTotZdhLV3R5BDaNB7Hmsg7g2vLFQ5g5nzc+rkTHkz6jbO26EkTPaLKDLCl62SwKTLvWJSQmJ2h2/H1d6a5Hydn1ewJIQH9VTHKb5vAmyHP0P0cRCSjHEdAAIAvJtv9HyyuUwzshdJRlmPKqsaDRiUw9Xb8idayvUuwIzfoHHB+dMWgAC0iyIP3SPZ9IDuvz88RXIgzi+em9J7+jgQeuu3XqzCB7F0Xa+cscQvWZuHeTcKC7sRntUsxSwERPp8NpG9kLIl6aPH16wMQULi/A9AaqQGGY/633ftBEq5ypIiijQp8OkLm6" +DOTENV_VAULT_CI_VERSION=163 # stage DOTENV_VAULT_STAGE="bfqZYD8oVLWMZ0JR5LICV+sB/btaXavszxZLxTfwSH8U5fg=" diff --git a/package.json b/package.json index 65dee48..dc61a49 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "publishConfig": { "access": "public" }, - "version": "1.0.234", + "version": "1.0.235", "license": "GPL-3.0-or-later", "name": "@clevercanyon/utilities.cfw", "description": "Utilities for JavaScript apps running in a Cloudflare Worker environment.", diff --git a/src/proxy.ts b/src/proxy.ts index 92ac30e..c3abd04 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -79,6 +79,7 @@ export const fetch = async (rcData: $cfw.StdRequestContextData, parseable: $type }) as RequiredFetchOptions; opts.headers = $http.parseHeaders(opts.headers) as $type.cfw.Headers; + if (!opts.headers.has('user-agent')) for (const [name, value] of Object.entries(await fetchꓺfakeUAHeaders(rcData))) { opts.headers.set(name, value); @@ -132,6 +133,9 @@ const fetchꓺviaSocket = async (rcData: $cfw.StdRequestContextData, url: $type. sockets = await import('cloudflare:sockets'); try { + // --- + // Socket setup. + const socket = sockets.connect({ hostname: opts.proxy.host, port: opts.proxy.port, @@ -160,7 +164,7 @@ const fetchꓺviaSocket = async (rcData: $cfw.StdRequestContextData, url: $type. let rawHTTPResponse = ''; // Initialize. - const textDecoder = new TextDecoder(), + const textDecoder = new TextDecoder(), // Initialize. reader = socket.readable.getReader() as $type.cfw.ReadableStreamDefaultReader; while (reader) { @@ -183,9 +187,7 @@ const fetchꓺviaSocket = async (rcData: $cfw.StdRequestContextData, url: $type. rawHTTPResponseHeaders = rawHTTPResponseCRLFIndex === -1 ? rawHTTPResponse : rawHTTPResponse.slice(0, rawHTTPResponseCRLFIndex).trim(), rawHTTPResponseBody = rawHTTPResponseCRLFIndex === -1 ? '' : rawHTTPResponse.slice(rawHTTPResponseCRLFIndex + 4).trim(); - void auditLogger.debug('fetchꓺviaSocket:', { rawHTTPResponseHeaders, rawHTTPResponseBody }); - - const responseStatus = Number(rawHTTPResponseHeaders.match(/^HTTP\/1\.0\s+([0-9]+)/iu)?.[1] || 0), + const responseStatus = Number(rawHTTPResponseHeaders.match(/^HTTP\/[0-9.]+\s+([0-9]+)/iu)?.[1] || 0), responseHeaders = $http.parseHeaders(rawHTTPResponseHeaders) as $type.cfw.Headers, responseBody = rawHTTPResponseBody; @@ -199,7 +201,7 @@ const fetchꓺviaSocket = async (rcData: $cfw.StdRequestContextData, url: $type. headers: responseHeaders, }); } catch (thrown) { - void auditLogger.warn('500: Fetch failure.', { thrown }); + void auditLogger.warn('Proxied fetch failure.', { thrown }); return new Response(null, { status: 500, statusText: $http.responseStatusText(500),