@push.rocks/smartproxy 25.17.10 → 26.0.0

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.
Files changed (179) hide show
  1. package/changelog.md +8 -0
  2. package/dist_rust/rustproxy_linux_amd64 +0 -0
  3. package/dist_rust/rustproxy_linux_arm64 +0 -0
  4. package/dist_ts/00_commitinfo_data.js +2 -2
  5. package/dist_ts/core/index.d.ts +0 -1
  6. package/dist_ts/core/index.js +1 -2
  7. package/dist_ts/core/models/index.d.ts +0 -1
  8. package/dist_ts/core/models/index.js +1 -2
  9. package/dist_ts/core/utils/index.d.ts +0 -12
  10. package/dist_ts/core/utils/index.js +1 -13
  11. package/dist_ts/index.d.ts +0 -3
  12. package/dist_ts/index.js +2 -7
  13. package/dist_ts/protocols/http/index.d.ts +0 -1
  14. package/dist_ts/protocols/http/index.js +1 -2
  15. package/dist_ts/protocols/index.d.ts +0 -7
  16. package/dist_ts/protocols/index.js +1 -8
  17. package/dist_ts/proxies/smart-proxy/socket-handler-server.js +6 -1
  18. package/dist_ts/proxies/smart-proxy/utils/route-helpers/socket-handlers.d.ts +0 -7
  19. package/dist_ts/proxies/smart-proxy/utils/route-helpers/socket-handlers.js +50 -51
  20. package/dist_ts/routing/index.d.ts +0 -1
  21. package/dist_ts/routing/index.js +1 -3
  22. package/package.json +1 -1
  23. package/ts/00_commitinfo_data.ts +1 -1
  24. package/ts/core/index.ts +0 -1
  25. package/ts/core/models/index.ts +0 -1
  26. package/ts/core/utils/index.ts +0 -12
  27. package/ts/index.ts +1 -7
  28. package/ts/protocols/http/index.ts +1 -2
  29. package/ts/protocols/index.ts +0 -7
  30. package/ts/proxies/smart-proxy/socket-handler-server.ts +6 -0
  31. package/ts/proxies/smart-proxy/utils/route-helpers/socket-handlers.ts +60 -59
  32. package/ts/routing/index.ts +0 -3
  33. package/dist_ts/core/events/index.d.ts +0 -4
  34. package/dist_ts/core/events/index.js +0 -5
  35. package/dist_ts/core/models/socket-augmentation.d.ts +0 -15
  36. package/dist_ts/core/models/socket-augmentation.js +0 -18
  37. package/dist_ts/core/utils/async-utils.d.ts +0 -81
  38. package/dist_ts/core/utils/async-utils.js +0 -216
  39. package/dist_ts/core/utils/binary-heap.d.ts +0 -73
  40. package/dist_ts/core/utils/binary-heap.js +0 -193
  41. package/dist_ts/core/utils/enhanced-connection-pool.d.ts +0 -110
  42. package/dist_ts/core/utils/enhanced-connection-pool.js +0 -325
  43. package/dist_ts/core/utils/fs-utils.d.ts +0 -144
  44. package/dist_ts/core/utils/fs-utils.js +0 -252
  45. package/dist_ts/core/utils/ip-utils.d.ts +0 -69
  46. package/dist_ts/core/utils/ip-utils.js +0 -270
  47. package/dist_ts/core/utils/lifecycle-component.d.ts +0 -59
  48. package/dist_ts/core/utils/lifecycle-component.js +0 -211
  49. package/dist_ts/core/utils/log-deduplicator.d.ts +0 -39
  50. package/dist_ts/core/utils/log-deduplicator.js +0 -305
  51. package/dist_ts/core/utils/security-utils.d.ts +0 -111
  52. package/dist_ts/core/utils/security-utils.js +0 -212
  53. package/dist_ts/core/utils/shared-security-manager.d.ts +0 -128
  54. package/dist_ts/core/utils/shared-security-manager.js +0 -362
  55. package/dist_ts/core/utils/socket-utils.d.ts +0 -63
  56. package/dist_ts/core/utils/socket-utils.js +0 -249
  57. package/dist_ts/core/utils/template-utils.d.ts +0 -37
  58. package/dist_ts/core/utils/template-utils.js +0 -104
  59. package/dist_ts/core/utils/validation-utils.d.ts +0 -61
  60. package/dist_ts/core/utils/validation-utils.js +0 -149
  61. package/dist_ts/core/utils/websocket-utils.d.ts +0 -22
  62. package/dist_ts/core/utils/websocket-utils.js +0 -30
  63. package/dist_ts/detection/detectors/http-detector.d.ts +0 -33
  64. package/dist_ts/detection/detectors/http-detector.js +0 -101
  65. package/dist_ts/detection/detectors/quick-detector.d.ts +0 -28
  66. package/dist_ts/detection/detectors/quick-detector.js +0 -131
  67. package/dist_ts/detection/detectors/routing-extractor.d.ts +0 -28
  68. package/dist_ts/detection/detectors/routing-extractor.js +0 -122
  69. package/dist_ts/detection/detectors/tls-detector.d.ts +0 -47
  70. package/dist_ts/detection/detectors/tls-detector.js +0 -183
  71. package/dist_ts/detection/index.d.ts +0 -17
  72. package/dist_ts/detection/index.js +0 -22
  73. package/dist_ts/detection/models/detection-types.d.ts +0 -87
  74. package/dist_ts/detection/models/detection-types.js +0 -5
  75. package/dist_ts/detection/models/interfaces.d.ts +0 -97
  76. package/dist_ts/detection/models/interfaces.js +0 -5
  77. package/dist_ts/detection/protocol-detector.d.ts +0 -79
  78. package/dist_ts/detection/protocol-detector.js +0 -253
  79. package/dist_ts/detection/utils/buffer-utils.d.ts +0 -61
  80. package/dist_ts/detection/utils/buffer-utils.js +0 -127
  81. package/dist_ts/detection/utils/fragment-manager.d.ts +0 -31
  82. package/dist_ts/detection/utils/fragment-manager.js +0 -53
  83. package/dist_ts/detection/utils/parser-utils.d.ts +0 -42
  84. package/dist_ts/detection/utils/parser-utils.js +0 -63
  85. package/dist_ts/protocols/common/fragment-handler.d.ts +0 -73
  86. package/dist_ts/protocols/common/fragment-handler.js +0 -121
  87. package/dist_ts/protocols/common/index.d.ts +0 -7
  88. package/dist_ts/protocols/common/index.js +0 -8
  89. package/dist_ts/protocols/common/types.d.ts +0 -68
  90. package/dist_ts/protocols/common/types.js +0 -7
  91. package/dist_ts/protocols/http/parser.d.ts +0 -58
  92. package/dist_ts/protocols/http/parser.js +0 -184
  93. package/dist_ts/protocols/proxy/index.d.ts +0 -5
  94. package/dist_ts/protocols/proxy/index.js +0 -6
  95. package/dist_ts/protocols/proxy/types.d.ts +0 -47
  96. package/dist_ts/protocols/proxy/types.js +0 -6
  97. package/dist_ts/protocols/tls/alerts/index.d.ts +0 -4
  98. package/dist_ts/protocols/tls/alerts/index.js +0 -5
  99. package/dist_ts/protocols/tls/alerts/tls-alert.d.ts +0 -150
  100. package/dist_ts/protocols/tls/alerts/tls-alert.js +0 -226
  101. package/dist_ts/protocols/tls/index.d.ts +0 -12
  102. package/dist_ts/protocols/tls/index.js +0 -27
  103. package/dist_ts/protocols/tls/sni/client-hello-parser.d.ts +0 -100
  104. package/dist_ts/protocols/tls/sni/client-hello-parser.js +0 -463
  105. package/dist_ts/protocols/tls/sni/index.d.ts +0 -5
  106. package/dist_ts/protocols/tls/sni/index.js +0 -6
  107. package/dist_ts/protocols/tls/sni/sni-extraction.d.ts +0 -58
  108. package/dist_ts/protocols/tls/sni/sni-extraction.js +0 -275
  109. package/dist_ts/protocols/tls/utils/index.d.ts +0 -4
  110. package/dist_ts/protocols/tls/utils/index.js +0 -5
  111. package/dist_ts/protocols/tls/utils/tls-utils.d.ts +0 -158
  112. package/dist_ts/protocols/tls/utils/tls-utils.js +0 -187
  113. package/dist_ts/protocols/websocket/constants.d.ts +0 -55
  114. package/dist_ts/protocols/websocket/constants.js +0 -58
  115. package/dist_ts/protocols/websocket/index.d.ts +0 -7
  116. package/dist_ts/protocols/websocket/index.js +0 -8
  117. package/dist_ts/protocols/websocket/types.d.ts +0 -47
  118. package/dist_ts/protocols/websocket/types.js +0 -5
  119. package/dist_ts/protocols/websocket/utils.d.ts +0 -25
  120. package/dist_ts/protocols/websocket/utils.js +0 -103
  121. package/dist_ts/routing/router/http-router.d.ts +0 -89
  122. package/dist_ts/routing/router/http-router.js +0 -205
  123. package/dist_ts/routing/router/index.d.ts +0 -5
  124. package/dist_ts/routing/router/index.js +0 -6
  125. package/dist_ts/tls/index.d.ts +0 -16
  126. package/dist_ts/tls/index.js +0 -24
  127. package/dist_ts/tls/sni/index.d.ts +0 -4
  128. package/dist_ts/tls/sni/index.js +0 -5
  129. package/dist_ts/tls/sni/sni-handler.d.ts +0 -154
  130. package/dist_ts/tls/sni/sni-handler.js +0 -191
  131. package/ts/core/events/index.ts +0 -3
  132. package/ts/core/models/socket-augmentation.ts +0 -38
  133. package/ts/core/utils/async-utils.ts +0 -275
  134. package/ts/core/utils/binary-heap.ts +0 -225
  135. package/ts/core/utils/enhanced-connection-pool.ts +0 -425
  136. package/ts/core/utils/fs-utils.ts +0 -270
  137. package/ts/core/utils/ip-utils.ts +0 -303
  138. package/ts/core/utils/lifecycle-component.ts +0 -251
  139. package/ts/core/utils/log-deduplicator.ts +0 -370
  140. package/ts/core/utils/security-utils.ts +0 -305
  141. package/ts/core/utils/shared-security-manager.ts +0 -470
  142. package/ts/core/utils/socket-utils.ts +0 -322
  143. package/ts/core/utils/template-utils.ts +0 -124
  144. package/ts/core/utils/validation-utils.ts +0 -177
  145. package/ts/core/utils/websocket-utils.ts +0 -33
  146. package/ts/detection/detectors/http-detector.ts +0 -127
  147. package/ts/detection/detectors/quick-detector.ts +0 -148
  148. package/ts/detection/detectors/routing-extractor.ts +0 -147
  149. package/ts/detection/detectors/tls-detector.ts +0 -223
  150. package/ts/detection/index.ts +0 -25
  151. package/ts/detection/models/detection-types.ts +0 -102
  152. package/ts/detection/models/interfaces.ts +0 -115
  153. package/ts/detection/protocol-detector.ts +0 -319
  154. package/ts/detection/utils/buffer-utils.ts +0 -141
  155. package/ts/detection/utils/fragment-manager.ts +0 -64
  156. package/ts/detection/utils/parser-utils.ts +0 -77
  157. package/ts/protocols/common/fragment-handler.ts +0 -167
  158. package/ts/protocols/common/index.ts +0 -8
  159. package/ts/protocols/common/types.ts +0 -76
  160. package/ts/protocols/http/parser.ts +0 -219
  161. package/ts/protocols/proxy/index.ts +0 -6
  162. package/ts/protocols/proxy/types.ts +0 -53
  163. package/ts/protocols/tls/alerts/index.ts +0 -3
  164. package/ts/protocols/tls/alerts/tls-alert.ts +0 -259
  165. package/ts/protocols/tls/index.ts +0 -37
  166. package/ts/protocols/tls/sni/client-hello-parser.ts +0 -629
  167. package/ts/protocols/tls/sni/index.ts +0 -6
  168. package/ts/protocols/tls/sni/sni-extraction.ts +0 -353
  169. package/ts/protocols/tls/utils/index.ts +0 -3
  170. package/ts/protocols/tls/utils/tls-utils.ts +0 -201
  171. package/ts/protocols/websocket/constants.ts +0 -60
  172. package/ts/protocols/websocket/index.ts +0 -8
  173. package/ts/protocols/websocket/types.ts +0 -53
  174. package/ts/protocols/websocket/utils.ts +0 -98
  175. package/ts/routing/router/http-router.ts +0 -266
  176. package/ts/routing/router/index.ts +0 -7
  177. package/ts/tls/index.ts +0 -29
  178. package/ts/tls/sni/index.ts +0 -3
  179. package/ts/tls/sni/sni-handler.ts +0 -264
@@ -1,64 +0,0 @@
1
- /**
2
- * Fragment Manager for Detection Module
3
- *
4
- * Manages fragmented protocol data using the shared fragment handler
5
- */
6
-
7
- import { FragmentHandler, type IFragmentOptions } from '../../protocols/common/fragment-handler.js';
8
- import type { IConnectionContext } from '../../protocols/common/types.js';
9
-
10
- /**
11
- * Detection-specific fragment manager
12
- */
13
- export class DetectionFragmentManager {
14
- private tlsFragments: FragmentHandler;
15
- private httpFragments: FragmentHandler;
16
-
17
- constructor() {
18
- // Configure fragment handlers with appropriate limits
19
- const tlsOptions: IFragmentOptions = {
20
- maxBufferSize: 16384, // TLS record max size
21
- timeout: 5000,
22
- cleanupInterval: 30000
23
- };
24
-
25
- const httpOptions: IFragmentOptions = {
26
- maxBufferSize: 8192, // HTTP header reasonable limit
27
- timeout: 5000,
28
- cleanupInterval: 30000
29
- };
30
-
31
- this.tlsFragments = new FragmentHandler(tlsOptions);
32
- this.httpFragments = new FragmentHandler(httpOptions);
33
- }
34
-
35
- /**
36
- * Get fragment handler for protocol type
37
- */
38
- getHandler(protocol: 'tls' | 'http'): FragmentHandler {
39
- return protocol === 'tls' ? this.tlsFragments : this.httpFragments;
40
- }
41
-
42
- /**
43
- * Create connection ID from context
44
- */
45
- static createConnectionId(context: IConnectionContext): string {
46
- return context.id || `${context.sourceIp}:${context.sourcePort}-${context.destIp}:${context.destPort}`;
47
- }
48
-
49
- /**
50
- * Clean up all handlers
51
- */
52
- cleanup(): void {
53
- this.tlsFragments.cleanup();
54
- this.httpFragments.cleanup();
55
- }
56
-
57
- /**
58
- * Destroy all handlers
59
- */
60
- destroy(): void {
61
- this.tlsFragments.destroy();
62
- this.httpFragments.destroy();
63
- }
64
- }
@@ -1,77 +0,0 @@
1
- /**
2
- * Parser utilities for protocol detection
3
- * Now delegates to protocol modules for actual parsing
4
- */
5
-
6
- import type { THttpMethod, TTlsVersion } from '../models/detection-types.js';
7
- import { HttpParser, HTTP_METHODS, HTTP_VERSIONS } from '../../protocols/http/index.js';
8
- import { tlsVersionToString as protocolTlsVersionToString } from '../../protocols/tls/index.js';
9
-
10
- // Re-export constants for backward compatibility
11
- export { HTTP_METHODS, HTTP_VERSIONS };
12
-
13
- /**
14
- * Parse HTTP request line
15
- */
16
- export function parseHttpRequestLine(line: string): {
17
- method: THttpMethod;
18
- path: string;
19
- version: string;
20
- } | null {
21
- // Delegate to protocol parser
22
- const result = HttpParser.parseRequestLine(line);
23
- return result ? {
24
- method: result.method as THttpMethod,
25
- path: result.path,
26
- version: result.version
27
- } : null;
28
- }
29
-
30
- /**
31
- * Parse HTTP header line
32
- */
33
- export function parseHttpHeader(line: string): { name: string; value: string } | null {
34
- // Delegate to protocol parser
35
- return HttpParser.parseHeaderLine(line);
36
- }
37
-
38
- /**
39
- * Parse HTTP headers from lines
40
- */
41
- export function parseHttpHeaders(lines: string[]): Record<string, string> {
42
- // Delegate to protocol parser
43
- return HttpParser.parseHeaders(lines);
44
- }
45
-
46
- /**
47
- * Convert TLS version bytes to version string
48
- */
49
- export function tlsVersionToString(major: number, minor: number): TTlsVersion | null {
50
- // Delegate to protocol parser
51
- return protocolTlsVersionToString(major, minor) as TTlsVersion;
52
- }
53
-
54
- /**
55
- * Extract domain from Host header value
56
- */
57
- export function extractDomainFromHost(hostHeader: string): string {
58
- // Delegate to protocol parser
59
- return HttpParser.extractDomainFromHost(hostHeader);
60
- }
61
-
62
- /**
63
- * Validate domain name
64
- */
65
- export function isValidDomain(domain: string): boolean {
66
- // Delegate to protocol parser
67
- return HttpParser.isValidDomain(domain);
68
- }
69
-
70
- /**
71
- * Check if string is a valid HTTP method
72
- */
73
- export function isHttpMethod(str: string): str is THttpMethod {
74
- // Delegate to protocol parser
75
- return HttpParser.isHttpMethod(str) && (str as THttpMethod) !== undefined;
76
- }
77
-
@@ -1,167 +0,0 @@
1
- /**
2
- * Shared Fragment Handler for Protocol Detection
3
- *
4
- * Provides unified fragment buffering and reassembly for protocols
5
- * that may span multiple TCP packets.
6
- */
7
-
8
- import { Buffer } from 'node:buffer';
9
-
10
- /**
11
- * Fragment tracking information
12
- */
13
- export interface IFragmentInfo {
14
- buffer: Buffer;
15
- timestamp: number;
16
- connectionId: string;
17
- }
18
-
19
- /**
20
- * Options for fragment handling
21
- */
22
- export interface IFragmentOptions {
23
- maxBufferSize?: number;
24
- timeout?: number;
25
- cleanupInterval?: number;
26
- }
27
-
28
- /**
29
- * Result of fragment processing
30
- */
31
- export interface IFragmentResult {
32
- isComplete: boolean;
33
- buffer?: Buffer;
34
- needsMoreData: boolean;
35
- error?: string;
36
- }
37
-
38
- /**
39
- * Shared fragment handler for protocol detection
40
- */
41
- export class FragmentHandler {
42
- private fragments = new Map<string, IFragmentInfo>();
43
- private cleanupTimer?: NodeJS.Timeout;
44
-
45
- constructor(private options: IFragmentOptions = {}) {
46
- // Start cleanup timer if not already running
47
- if (options.cleanupInterval && !this.cleanupTimer) {
48
- this.cleanupTimer = setInterval(
49
- () => this.cleanup(),
50
- options.cleanupInterval
51
- );
52
- // Don't let this timer prevent process exit
53
- if (this.cleanupTimer.unref) {
54
- this.cleanupTimer.unref();
55
- }
56
- }
57
- }
58
-
59
- /**
60
- * Add a fragment for a connection
61
- */
62
- addFragment(connectionId: string, fragment: Buffer): IFragmentResult {
63
- const existing = this.fragments.get(connectionId);
64
-
65
- if (existing) {
66
- // Append to existing buffer
67
- const newBuffer = Buffer.concat([existing.buffer, fragment]);
68
-
69
- // Check size limit
70
- const maxSize = this.options.maxBufferSize || 65536;
71
- if (newBuffer.length > maxSize) {
72
- this.fragments.delete(connectionId);
73
- return {
74
- isComplete: false,
75
- needsMoreData: false,
76
- error: 'Buffer size exceeded maximum allowed'
77
- };
78
- }
79
-
80
- // Update fragment info
81
- this.fragments.set(connectionId, {
82
- buffer: newBuffer,
83
- timestamp: Date.now(),
84
- connectionId
85
- });
86
-
87
- return {
88
- isComplete: false,
89
- buffer: newBuffer,
90
- needsMoreData: true
91
- };
92
- } else {
93
- // New fragment
94
- this.fragments.set(connectionId, {
95
- buffer: fragment,
96
- timestamp: Date.now(),
97
- connectionId
98
- });
99
-
100
- return {
101
- isComplete: false,
102
- buffer: fragment,
103
- needsMoreData: true
104
- };
105
- }
106
- }
107
-
108
- /**
109
- * Get the current buffer for a connection
110
- */
111
- getBuffer(connectionId: string): Buffer | undefined {
112
- return this.fragments.get(connectionId)?.buffer;
113
- }
114
-
115
- /**
116
- * Mark a connection as complete and clean up
117
- */
118
- complete(connectionId: string): void {
119
- this.fragments.delete(connectionId);
120
- }
121
-
122
- /**
123
- * Check if we're tracking a connection
124
- */
125
- hasConnection(connectionId: string): boolean {
126
- return this.fragments.has(connectionId);
127
- }
128
-
129
- /**
130
- * Clean up expired fragments
131
- */
132
- cleanup(): void {
133
- const now = Date.now();
134
- const timeout = this.options.timeout || 5000;
135
-
136
- for (const [connectionId, info] of this.fragments.entries()) {
137
- if (now - info.timestamp > timeout) {
138
- this.fragments.delete(connectionId);
139
- }
140
- }
141
- }
142
-
143
- /**
144
- * Clear all fragments
145
- */
146
- clear(): void {
147
- this.fragments.clear();
148
- }
149
-
150
- /**
151
- * Destroy the handler and clean up resources
152
- */
153
- destroy(): void {
154
- if (this.cleanupTimer) {
155
- clearInterval(this.cleanupTimer);
156
- this.cleanupTimer = undefined;
157
- }
158
- this.clear();
159
- }
160
-
161
- /**
162
- * Get the number of tracked connections
163
- */
164
- get size(): number {
165
- return this.fragments.size;
166
- }
167
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Common Protocol Infrastructure
3
- *
4
- * Shared utilities and types for protocol handling
5
- */
6
-
7
- export * from './fragment-handler.js';
8
- export * from './types.js';
@@ -1,76 +0,0 @@
1
- /**
2
- * Common Protocol Types
3
- *
4
- * Shared types used across different protocol implementations
5
- */
6
-
7
- /**
8
- * Supported protocol types
9
- */
10
- export type TProtocolType = 'tls' | 'http' | 'https' | 'websocket' | 'unknown';
11
-
12
- /**
13
- * Protocol detection result
14
- */
15
- export interface IProtocolDetectionResult {
16
- protocol: TProtocolType;
17
- confidence: number; // 0-100
18
- requiresMoreData?: boolean;
19
- metadata?: {
20
- version?: string;
21
- method?: string;
22
- [key: string]: any;
23
- };
24
- }
25
-
26
- /**
27
- * Routing information extracted from protocols
28
- */
29
- export interface IRoutingInfo {
30
- domain?: string;
31
- port?: number;
32
- path?: string;
33
- protocol: TProtocolType;
34
- }
35
-
36
- /**
37
- * Connection context for protocol operations
38
- */
39
- export interface IConnectionContext {
40
- id: string;
41
- sourceIp?: string;
42
- sourcePort?: number;
43
- destIp?: string;
44
- destPort?: number;
45
- timestamp?: number;
46
- }
47
-
48
- /**
49
- * Protocol detection options
50
- */
51
- export interface IProtocolDetectionOptions {
52
- quickMode?: boolean; // Only do minimal detection
53
- extractRouting?: boolean; // Extract routing information
54
- maxWaitTime?: number; // Max time to wait for complete data
55
- maxBufferSize?: number; // Max buffer size for fragmented data
56
- }
57
-
58
- /**
59
- * Base interface for protocol detectors
60
- */
61
- export interface IProtocolDetector {
62
- /**
63
- * Check if this detector can handle the data
64
- */
65
- canHandle(data: Buffer): boolean;
66
-
67
- /**
68
- * Perform quick detection (first few bytes only)
69
- */
70
- quickDetect(data: Buffer): IProtocolDetectionResult;
71
-
72
- /**
73
- * Extract routing information if possible
74
- */
75
- extractRouting?(data: Buffer, context?: IConnectionContext): IRoutingInfo | null;
76
- }
@@ -1,219 +0,0 @@
1
- /**
2
- * HTTP Protocol Parser
3
- * Generic HTTP parsing utilities
4
- */
5
-
6
- import { HTTP_METHODS, type THttpMethod, type THttpVersion } from './constants.js';
7
- import type { IHttpRequestLine, IHttpHeader } from './types.js';
8
-
9
- /**
10
- * HTTP parser utilities
11
- */
12
- export class HttpParser {
13
- /**
14
- * Check if string is a valid HTTP method
15
- */
16
- static isHttpMethod(str: string): str is THttpMethod {
17
- return HTTP_METHODS.includes(str as THttpMethod);
18
- }
19
-
20
- /**
21
- * Parse HTTP request line
22
- */
23
- static parseRequestLine(line: string): IHttpRequestLine | null {
24
- const parts = line.trim().split(' ');
25
-
26
- if (parts.length !== 3) {
27
- return null;
28
- }
29
-
30
- const [method, path, version] = parts;
31
-
32
- // Validate method
33
- if (!this.isHttpMethod(method)) {
34
- return null;
35
- }
36
-
37
- // Validate version
38
- if (!version.startsWith('HTTP/')) {
39
- return null;
40
- }
41
-
42
- return {
43
- method: method as THttpMethod,
44
- path,
45
- version: version as THttpVersion
46
- };
47
- }
48
-
49
- /**
50
- * Parse HTTP header line
51
- */
52
- static parseHeaderLine(line: string): IHttpHeader | null {
53
- const colonIndex = line.indexOf(':');
54
-
55
- if (colonIndex === -1) {
56
- return null;
57
- }
58
-
59
- const name = line.slice(0, colonIndex).trim();
60
- const value = line.slice(colonIndex + 1).trim();
61
-
62
- if (!name) {
63
- return null;
64
- }
65
-
66
- return { name, value };
67
- }
68
-
69
- /**
70
- * Parse HTTP headers from lines
71
- */
72
- static parseHeaders(lines: string[]): Record<string, string> {
73
- const headers: Record<string, string> = {};
74
-
75
- for (const line of lines) {
76
- const header = this.parseHeaderLine(line);
77
- if (header) {
78
- // Convert header names to lowercase for consistency
79
- headers[header.name.toLowerCase()] = header.value;
80
- }
81
- }
82
-
83
- return headers;
84
- }
85
-
86
- /**
87
- * Extract domain from Host header value
88
- */
89
- static extractDomainFromHost(hostHeader: string): string {
90
- // Remove port if present
91
- const colonIndex = hostHeader.lastIndexOf(':');
92
- if (colonIndex !== -1) {
93
- // Check if it's not part of IPv6 address
94
- const beforeColon = hostHeader.slice(0, colonIndex);
95
- if (!beforeColon.includes(']')) {
96
- return beforeColon;
97
- }
98
- }
99
- return hostHeader;
100
- }
101
-
102
- /**
103
- * Validate domain name
104
- */
105
- static isValidDomain(domain: string): boolean {
106
- // Basic domain validation
107
- if (!domain || domain.length > 253) {
108
- return false;
109
- }
110
-
111
- // Check for valid characters and structure
112
- const domainRegex = /^(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\.[A-Za-z0-9-]{1,63})*$/;
113
- return domainRegex.test(domain);
114
- }
115
-
116
- /**
117
- * Extract line from buffer
118
- */
119
- static extractLine(buffer: Buffer, offset: number = 0): { line: string; nextOffset: number } | null {
120
- // Look for CRLF
121
- const crlfIndex = buffer.indexOf('\r\n', offset);
122
- if (crlfIndex === -1) {
123
- // Look for just LF
124
- const lfIndex = buffer.indexOf('\n', offset);
125
- if (lfIndex === -1) {
126
- return null;
127
- }
128
-
129
- return {
130
- line: buffer.slice(offset, lfIndex).toString('utf8'),
131
- nextOffset: lfIndex + 1
132
- };
133
- }
134
-
135
- return {
136
- line: buffer.slice(offset, crlfIndex).toString('utf8'),
137
- nextOffset: crlfIndex + 2
138
- };
139
- }
140
-
141
- /**
142
- * Check if buffer contains printable ASCII
143
- */
144
- static isPrintableAscii(buffer: Buffer, length?: number): boolean {
145
- const checkLength = Math.min(length || buffer.length, buffer.length);
146
-
147
- for (let i = 0; i < checkLength; i++) {
148
- const byte = buffer[i];
149
- // Allow printable ASCII (32-126) plus tab (9), LF (10), and CR (13)
150
- if (byte < 32 || byte > 126) {
151
- if (byte !== 9 && byte !== 10 && byte !== 13) {
152
- return false;
153
- }
154
- }
155
- }
156
-
157
- return true;
158
- }
159
-
160
- /**
161
- * Quick check if buffer starts with HTTP method
162
- */
163
- static quickCheck(buffer: Buffer): boolean {
164
- if (buffer.length < 3) {
165
- return false;
166
- }
167
-
168
- // Check common HTTP methods
169
- const start = buffer.slice(0, 7).toString('ascii');
170
- return start.startsWith('GET ') ||
171
- start.startsWith('POST ') ||
172
- start.startsWith('PUT ') ||
173
- start.startsWith('DELETE ') ||
174
- start.startsWith('HEAD ') ||
175
- start.startsWith('OPTIONS') ||
176
- start.startsWith('PATCH ') ||
177
- start.startsWith('CONNECT') ||
178
- start.startsWith('TRACE ');
179
- }
180
-
181
- /**
182
- * Parse query string
183
- */
184
- static parseQueryString(queryString: string): Record<string, string> {
185
- const params: Record<string, string> = {};
186
-
187
- if (!queryString) {
188
- return params;
189
- }
190
-
191
- // Remove leading '?' if present
192
- if (queryString.startsWith('?')) {
193
- queryString = queryString.slice(1);
194
- }
195
-
196
- const pairs = queryString.split('&');
197
- for (const pair of pairs) {
198
- const [key, value] = pair.split('=');
199
- if (key) {
200
- params[decodeURIComponent(key)] = value ? decodeURIComponent(value) : '';
201
- }
202
- }
203
-
204
- return params;
205
- }
206
-
207
- /**
208
- * Build query string from params
209
- */
210
- static buildQueryString(params: Record<string, string>): string {
211
- const pairs: string[] = [];
212
-
213
- for (const [key, value] of Object.entries(params)) {
214
- pairs.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
215
- }
216
-
217
- return pairs.length > 0 ? '?' + pairs.join('&') : '';
218
- }
219
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * PROXY Protocol Module
3
- * Type definitions for HAProxy PROXY protocol v1/v2
4
- */
5
-
6
- export * from './types.js';
@@ -1,53 +0,0 @@
1
- /**
2
- * PROXY Protocol Type Definitions
3
- * Based on HAProxy PROXY protocol specification
4
- */
5
-
6
- /**
7
- * PROXY protocol version
8
- */
9
- export type TProxyProtocolVersion = 'v1' | 'v2';
10
-
11
- /**
12
- * Connection protocol type
13
- */
14
- export type TProxyProtocol = 'TCP4' | 'TCP6' | 'UDP4' | 'UDP6' | 'UNKNOWN';
15
-
16
- /**
17
- * Interface representing parsed PROXY protocol information
18
- */
19
- export interface IProxyInfo {
20
- protocol: TProxyProtocol;
21
- sourceIP: string;
22
- sourcePort: number;
23
- destinationIP: string;
24
- destinationPort: number;
25
- }
26
-
27
- /**
28
- * Interface for parse result including remaining data
29
- */
30
- export interface IProxyParseResult {
31
- proxyInfo: IProxyInfo | null;
32
- remainingData: Buffer;
33
- }
34
-
35
- /**
36
- * PROXY protocol v2 header format
37
- */
38
- export interface IProxyV2Header {
39
- signature: Buffer;
40
- versionCommand: number;
41
- family: number;
42
- length: number;
43
- }
44
-
45
- /**
46
- * Connection information for PROXY protocol
47
- */
48
- export interface IProxyConnectionInfo {
49
- sourceIp?: string;
50
- sourcePort?: number;
51
- destIp?: string;
52
- destPort?: number;
53
- }
@@ -1,3 +0,0 @@
1
- /**
2
- * TLS alerts
3
- */