diff --git a/changelog.md b/changelog.md index 38ac631..80e1061 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2025-11-16 - 4.4.1 - fix(core_node) +Fix unix socket URL parsing and handling in CoreRequest + +- CoreRequest.parseUnixSocketUrl now strips http:// and https:// prefixes so it correctly parses both full URLs (e.g. http://unix:/path/to/socket:/route) and already-stripped unix: paths. +- Node.js CoreRequest now passes the original request URL to parseUnixSocketUrl instead of options.path, preventing incorrect socketPath/path extraction. +- Fixes connection failures when using unix socket URLs (for example when targeting Docker via http://unix:/var/run/docker.sock:/v1.24/...). + ## 2025-11-16 - 4.4.0 - feat(core) Add Bun and Deno runtime support, unify core loader, unix-socket support and cross-runtime streaming/tests diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index a5d194d..5a91150 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartrequest', - version: '4.4.0', + version: '4.4.1', description: 'A module for modern HTTP/HTTPS requests with support for form data, file uploads, JSON, binary data, streams, and more.' } diff --git a/ts/core_base/request.ts b/ts/core_base/request.ts index ce2c279..d375a0d 100644 --- a/ts/core_base/request.ts +++ b/ts/core_base/request.ts @@ -17,10 +17,22 @@ export abstract class CoreRequest< /** * Parses socket path and route from unix socket URL + * Handles both full URLs (http://unix:/path/to/socket:/route) and pre-stripped paths (unix:/path/to/socket:/route) */ static parseUnixSocketUrl(url: string): { socketPath: string; path: string } { + // Strip http:// or https:// prefix if present + // This makes the method work with both full URLs and pre-stripped paths + let cleanUrl = url; + if (cleanUrl.startsWith('http://')) { + cleanUrl = cleanUrl.substring('http://'.length); + } else if (cleanUrl.startsWith('https://')) { + cleanUrl = cleanUrl.substring('https://'.length); + } + + // Parse the socket path and HTTP path + // Format: unix:/path/to/socket:/route/path const parseRegex = /(.*):(.*)/; - const result = parseRegex.exec(url); + const result = parseRegex.exec(cleanUrl); return { socketPath: result[1], path: result[2], diff --git a/ts/core_node/request.ts b/ts/core_node/request.ts index d8c1cc4..dcb918f 100644 --- a/ts/core_node/request.ts +++ b/ts/core_node/request.ts @@ -86,9 +86,7 @@ export class CoreRequest extends AbstractCoreRequest< // Handle unix socket URLs if (CoreRequest.isUnixSocket(this.url)) { - const { socketPath, path } = CoreRequest.parseUnixSocketUrl( - this.options.path, - ); + const { socketPath, path } = CoreRequest.parseUnixSocketUrl(this.url); this.options.socketPath = socketPath; this.options.path = path; }