httpcloak 1.5.2 → 1.5.4

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/README.md CHANGED
@@ -48,6 +48,19 @@ async function main() {
48
48
  main();
49
49
  ```
50
50
 
51
+ ### ES Modules
52
+
53
+ ```javascript
54
+ import { Session } from "httpcloak";
55
+
56
+ const session = new Session({ preset: "chrome-143" });
57
+
58
+ const response = await session.get("https://example.com");
59
+ console.log(response.text);
60
+
61
+ session.close();
62
+ ```
63
+
51
64
  ### Synchronous Usage
52
65
 
53
66
  ```javascript
@@ -99,6 +112,78 @@ session.postCb(
99
112
  );
100
113
  ```
101
114
 
115
+ ### Streaming Downloads
116
+
117
+ For large downloads, use streaming to avoid loading entire response into memory:
118
+
119
+ ```javascript
120
+ const { Session } = require("httpcloak");
121
+ const fs = require("fs");
122
+
123
+ async function downloadFile() {
124
+ const session = new Session({ preset: "chrome-143" });
125
+
126
+ try {
127
+ // Start streaming request
128
+ const stream = session.getStream("https://example.com/large-file.zip");
129
+
130
+ console.log(`Status: ${stream.statusCode}`);
131
+ console.log(`Content-Length: ${stream.contentLength}`);
132
+ console.log(`Protocol: ${stream.protocol}`);
133
+
134
+ // Read in chunks
135
+ const file = fs.createWriteStream("downloaded-file.zip");
136
+ let totalBytes = 0;
137
+ let chunk;
138
+
139
+ while ((chunk = stream.readChunk(65536)) !== null) {
140
+ file.write(chunk);
141
+ totalBytes += chunk.length;
142
+ console.log(`Downloaded ${totalBytes} bytes...`);
143
+ }
144
+
145
+ file.end();
146
+ stream.close();
147
+ console.log(`Download complete: ${totalBytes} bytes`);
148
+ } finally {
149
+ session.close();
150
+ }
151
+ }
152
+
153
+ downloadFile();
154
+ ```
155
+
156
+ ### Streaming with All Methods
157
+
158
+ ```javascript
159
+ const { Session } = require("httpcloak");
160
+
161
+ const session = new Session({ preset: "chrome-143" });
162
+
163
+ // Stream GET
164
+ const getStream = session.getStream("https://example.com/data");
165
+
166
+ // Stream POST
167
+ const postStream = session.postStream("https://example.com/upload", "data");
168
+
169
+ // Stream with custom options
170
+ const customStream = session.requestStream({
171
+ method: "PUT",
172
+ url: "https://example.com/resource",
173
+ headers: { "Content-Type": "application/json" },
174
+ body: JSON.stringify({ key: "value" }),
175
+ });
176
+
177
+ // Read response
178
+ let chunk;
179
+ while ((chunk = customStream.readChunk(65536)) !== null) {
180
+ console.log(`Received ${chunk.length} bytes`);
181
+ }
182
+ customStream.close();
183
+
184
+ session.close();
185
+ ```
186
+
102
187
  ## Proxy Support
103
188
 
104
189
  HTTPCloak supports HTTP, SOCKS5, and HTTP/3 (MASQUE) proxies with full fingerprint preservation.
@@ -165,6 +250,20 @@ const response = await session.get("https://www.cloudflare.com/cdn-cgi/trace");
165
250
  console.log(response.protocol); // h3
166
251
  ```
167
252
 
253
+ ### Split Proxy Configuration
254
+
255
+ Use different proxies for TCP (HTTP/1.1, HTTP/2) and UDP (HTTP/3) traffic:
256
+
257
+ ```javascript
258
+ const { Session } = require("httpcloak");
259
+
260
+ const session = new Session({
261
+ preset: "chrome-143",
262
+ tcpProxy: "http://tcp-proxy:port", // For HTTP/1.1, HTTP/2
263
+ udpProxy: "https://masque-proxy:port", // For HTTP/3
264
+ });
265
+ ```
266
+
168
267
  ## Advanced Features
169
268
 
170
269
  ### Encrypted Client Hello (ECH)
@@ -225,19 +324,47 @@ const { Session } = require("httpcloak");
225
324
 
226
325
  const session = new Session();
227
326
 
327
+ // Set a cookie
328
+ session.setCookie("session_id", "abc123");
329
+
228
330
  // Get all cookies
229
331
  const cookies = session.getCookies();
230
332
  console.log(cookies);
231
333
 
232
- // Set a cookie
233
- session.setCookie("session_id", "abc123");
234
-
235
334
  // Access cookies as property
236
335
  console.log(session.cookies);
237
336
 
337
+ // Clear a cookie
338
+ session.clearCookie("session_id");
339
+
340
+ // Clear all cookies
341
+ session.clearCookies();
342
+
238
343
  session.close();
239
344
  ```
240
345
 
346
+ ## Session Configuration
347
+
348
+ ```javascript
349
+ const { Session } = require("httpcloak");
350
+
351
+ const session = new Session({
352
+ preset: "chrome-143", // Browser fingerprint preset
353
+ proxy: null, // Proxy URL
354
+ tcpProxy: null, // Separate TCP proxy
355
+ udpProxy: null, // Separate UDP proxy (MASQUE)
356
+ timeout: 30, // Request timeout in seconds
357
+ httpVersion: "auto", // "auto", "h1", "h2", "h3"
358
+ verify: true, // SSL certificate verification
359
+ allowRedirects: true, // Follow redirects
360
+ maxRedirects: 10, // Maximum redirect count
361
+ retry: 3, // Retry count on failure
362
+ preferIpv4: false, // Prefer IPv4 over IPv6
363
+ connectTo: null, // Domain fronting map
364
+ echConfigDomain: null, // ECH config domain
365
+ });
366
+ ```
367
+
241
368
  ## Available Presets
242
369
 
243
370
  ```javascript
@@ -250,28 +377,90 @@ console.log(availablePresets());
250
377
 
251
378
  ## Response Object
252
379
 
380
+ ### Standard Response
381
+
253
382
  ```javascript
254
383
  const response = await session.get("https://example.com");
255
384
 
256
- response.statusCode; // number: HTTP status code
257
- response.headers; // object: Response headers
258
- response.body; // Buffer: Raw response body
259
- response.text; // string: Response body as text
260
- response.finalUrl; // string: Final URL after redirects
261
- response.protocol; // string: Protocol used (http/1.1, h2, h3)
262
- response.json(); // Parse response body as JSON
385
+ response.statusCode; // number: HTTP status code
386
+ response.headers; // object: Response headers (values are arrays)
387
+ response.body; // Buffer: Raw response body
388
+ response.text; // string: Response body as text
389
+ response.finalUrl; // string: Final URL after redirects
390
+ response.protocol; // string: Protocol used (http/1.1, h2, h3)
391
+ response.ok; // boolean: True if status < 400
392
+ response.cookies; // array: Cookies from response
393
+ response.history; // array: Redirect history
394
+
395
+ // Get specific header
396
+ const contentType = response.getHeader("Content-Type");
397
+ const allCookies = response.getHeaders("Set-Cookie");
398
+
399
+ // Parse JSON
400
+ const data = response.json();
401
+ ```
402
+
403
+ ### Streaming Response
404
+
405
+ ```javascript
406
+ const stream = session.getStream("https://example.com");
407
+
408
+ stream.statusCode; // number: HTTP status code
409
+ stream.headers; // object: Response headers (values are arrays)
410
+ stream.contentLength; // number: Content length (-1 if unknown)
411
+ stream.finalUrl; // string: Final URL after redirects
412
+ stream.protocol; // string: Protocol used
413
+
414
+ // Read all bytes
415
+ const data = stream.readAll();
416
+
417
+ // Read in chunks (memory efficient)
418
+ let chunk;
419
+ while ((chunk = stream.readChunk(65536)) !== null) {
420
+ process(chunk);
421
+ }
422
+
423
+ stream.close();
263
424
  ```
264
425
 
265
- ## Custom Requests
426
+ ## HTTP Methods
266
427
 
267
428
  ```javascript
268
- const response = await session.request({
429
+ const { Session } = require("httpcloak");
430
+
431
+ const session = new Session({ preset: "chrome-143" });
432
+
433
+ // GET
434
+ const response = await session.get("https://example.com");
435
+
436
+ // POST
437
+ const postResponse = await session.post("https://example.com", { key: "value" });
438
+
439
+ // PUT
440
+ const putResponse = await session.put("https://example.com", { key: "value" });
441
+
442
+ // PATCH
443
+ const patchResponse = await session.patch("https://example.com", { key: "value" });
444
+
445
+ // DELETE
446
+ const deleteResponse = await session.delete("https://example.com");
447
+
448
+ // HEAD
449
+ const headResponse = await session.head("https://example.com");
450
+
451
+ // OPTIONS
452
+ const optionsResponse = await session.options("https://example.com");
453
+
454
+ // Custom request
455
+ const customResponse = await session.request({
269
456
  method: "PUT",
270
457
  url: "https://api.example.com/resource",
271
458
  headers: { "X-Custom": "value" },
272
459
  body: { data: "value" },
273
460
  timeout: 60,
274
461
  });
462
+
463
+ session.close();
275
464
  ```
276
465
 
277
466
  ## Error Handling
@@ -299,13 +488,22 @@ session.close();
299
488
  HTTPCloak includes TypeScript definitions out of the box:
300
489
 
301
490
  ```typescript
302
- import { Session, Response, HTTPCloakError } from "httpcloak";
491
+ import { Session, Response, StreamResponse, HTTPCloakError } from "httpcloak";
303
492
 
304
493
  const session = new Session({ preset: "chrome-143" });
305
494
 
306
495
  async function fetchData(): Promise<Response> {
307
496
  return session.get("https://example.com");
308
497
  }
498
+
499
+ async function downloadLargeFile(): Promise<void> {
500
+ const stream: StreamResponse = session.getStream("https://example.com/file");
501
+ let chunk: Buffer | null;
502
+ while ((chunk = stream.readChunk(65536)) !== null) {
503
+ // Process chunk
504
+ }
505
+ stream.close();
506
+ }
309
507
  ```
310
508
 
311
509
  ## Platform Support
@@ -313,6 +511,7 @@ async function fetchData(): Promise<Response> {
313
511
  - Linux (x64, arm64)
314
512
  - macOS (x64, arm64)
315
513
  - Windows (x64, arm64)
514
+ - Node.js 16+
316
515
 
317
516
  ## License
318
517
 
package/lib/index.d.ts CHANGED
@@ -64,6 +64,10 @@ export interface SessionOptions {
64
64
  preset?: string;
65
65
  /** Proxy URL (e.g., "http://user:pass@host:port" or "socks5://host:port") */
66
66
  proxy?: string;
67
+ /** Proxy URL for TCP protocols (HTTP/1.1, HTTP/2) - use with udpProxy for split config */
68
+ tcpProxy?: string;
69
+ /** Proxy URL for UDP protocols (HTTP/3 via MASQUE) - use with tcpProxy for split config */
70
+ udpProxy?: string;
67
71
  /** Request timeout in seconds (default: 30) */
68
72
  timeout?: number;
69
73
  /** HTTP version: "auto", "h1", "h2", "h3" (default: "auto") */