httpcloak 1.5.3 → 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/lib/index.js CHANGED
@@ -731,6 +731,11 @@ function getLib() {
731
731
  httpcloak_response_free: nativeLibHandle.func("httpcloak_response_free", "void", ["int64"]),
732
732
  // Combined finalize function (copy + metadata + free in one call)
733
733
  httpcloak_response_finalize: nativeLibHandle.func("httpcloak_response_finalize", "str", ["int64", "void*", "int"]),
734
+ // Session persistence functions
735
+ httpcloak_session_save: nativeLibHandle.func("httpcloak_session_save", "str", ["int64", "str"]),
736
+ httpcloak_session_load: nativeLibHandle.func("httpcloak_session_load", "int64", ["str"]),
737
+ httpcloak_session_marshal: nativeLibHandle.func("httpcloak_session_marshal", "str", ["int64"]),
738
+ httpcloak_session_unmarshal: nativeLibHandle.func("httpcloak_session_unmarshal", "int64", ["str"]),
734
739
  };
735
740
  }
736
741
  return lib;
@@ -1612,6 +1617,127 @@ class Session {
1612
1617
  return this.getCookies();
1613
1618
  }
1614
1619
 
1620
+ // ===========================================================================
1621
+ // Session Persistence
1622
+ // ===========================================================================
1623
+
1624
+ /**
1625
+ * Save session state (cookies, TLS sessions) to a file.
1626
+ *
1627
+ * This allows you to persist session state across program runs,
1628
+ * including cookies and TLS session tickets for faster resumption.
1629
+ *
1630
+ * @param {string} path - Path to save the session file
1631
+ *
1632
+ * Example:
1633
+ * const session = new httpcloak.Session({ preset: "chrome-143" });
1634
+ * await session.get("https://example.com"); // Acquire cookies
1635
+ * session.save("session.json");
1636
+ *
1637
+ * // Later, restore the session
1638
+ * const session = httpcloak.Session.load("session.json");
1639
+ */
1640
+ save(path) {
1641
+ const result = this._lib.httpcloak_session_save(this._handle, path);
1642
+ if (result) {
1643
+ const data = JSON.parse(result);
1644
+ if (data.error) {
1645
+ throw new HTTPCloakError(data.error);
1646
+ }
1647
+ }
1648
+ }
1649
+
1650
+ /**
1651
+ * Export session state to JSON string.
1652
+ *
1653
+ * @returns {string} JSON string containing session state
1654
+ *
1655
+ * Example:
1656
+ * const sessionData = session.marshal();
1657
+ * // Store sessionData in database, cache, etc.
1658
+ *
1659
+ * // Later, restore the session
1660
+ * const session = httpcloak.Session.unmarshal(sessionData);
1661
+ */
1662
+ marshal() {
1663
+ const result = this._lib.httpcloak_session_marshal(this._handle);
1664
+ if (!result) {
1665
+ throw new HTTPCloakError("Failed to marshal session");
1666
+ }
1667
+
1668
+ // Check for error
1669
+ try {
1670
+ const data = JSON.parse(result);
1671
+ if (data && typeof data === "object" && data.error) {
1672
+ throw new HTTPCloakError(data.error);
1673
+ }
1674
+ } catch (e) {
1675
+ if (e instanceof HTTPCloakError) throw e;
1676
+ // Not an error response, just JSON parse failed - return as is
1677
+ }
1678
+
1679
+ return result;
1680
+ }
1681
+
1682
+ /**
1683
+ * Load a session from a file.
1684
+ *
1685
+ * This restores session state including cookies and TLS session tickets.
1686
+ * The session uses the same preset that was used when it was saved.
1687
+ *
1688
+ * @param {string} path - Path to the session file
1689
+ * @returns {Session} Restored Session object
1690
+ *
1691
+ * Example:
1692
+ * const session = httpcloak.Session.load("session.json");
1693
+ * const r = await session.get("https://example.com"); // Uses restored cookies
1694
+ */
1695
+ static load(path) {
1696
+ const lib = getLib();
1697
+ const handle = lib.httpcloak_session_load(path);
1698
+
1699
+ if (handle < 0 || handle === 0n) {
1700
+ throw new HTTPCloakError(`Failed to load session from ${path}`);
1701
+ }
1702
+
1703
+ // Create a new Session instance without calling constructor
1704
+ const session = Object.create(Session.prototype);
1705
+ session._lib = lib;
1706
+ session._handle = handle;
1707
+ session.headers = {};
1708
+ session.auth = null;
1709
+
1710
+ return session;
1711
+ }
1712
+
1713
+ /**
1714
+ * Load a session from JSON string.
1715
+ *
1716
+ * @param {string} data - JSON string containing session state
1717
+ * @returns {Session} Restored Session object
1718
+ *
1719
+ * Example:
1720
+ * // Retrieve sessionData from database, cache, etc.
1721
+ * const session = httpcloak.Session.unmarshal(sessionData);
1722
+ */
1723
+ static unmarshal(data) {
1724
+ const lib = getLib();
1725
+ const handle = lib.httpcloak_session_unmarshal(data);
1726
+
1727
+ if (handle < 0 || handle === 0n) {
1728
+ throw new HTTPCloakError("Failed to unmarshal session");
1729
+ }
1730
+
1731
+ // Create a new Session instance without calling constructor
1732
+ const session = Object.create(Session.prototype);
1733
+ session._lib = lib;
1734
+ session._handle = handle;
1735
+ session.headers = {};
1736
+ session.auth = null;
1737
+
1738
+ return session;
1739
+ }
1740
+
1615
1741
  // ===========================================================================
1616
1742
  // Streaming Methods
1617
1743
  // ===========================================================================
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@httpcloak/darwin-arm64",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "description": "HTTPCloak native binary for darwin arm64",
5
5
  "os": [
6
6
  "darwin"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@httpcloak/darwin-x64",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "description": "HTTPCloak native binary for darwin x64",
5
5
  "os": [
6
6
  "darwin"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@httpcloak/linux-arm64",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "description": "HTTPCloak native binary for linux arm64",
5
5
  "os": [
6
6
  "linux"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@httpcloak/linux-x64",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "description": "HTTPCloak native binary for linux x64",
5
5
  "os": [
6
6
  "linux"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@httpcloak/win32-arm64",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "description": "HTTPCloak native binary for win32 arm64",
5
5
  "os": [
6
6
  "win32"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@httpcloak/win32-x64",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "description": "HTTPCloak native binary for win32 x64",
5
5
  "os": [
6
6
  "win32"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "httpcloak",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "description": "Browser fingerprint emulation HTTP client with HTTP/1.1, HTTP/2, and HTTP/3 support",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",
@@ -49,11 +49,11 @@
49
49
  "koffi": "^2.9.0"
50
50
  },
51
51
  "optionalDependencies": {
52
- "@httpcloak/linux-x64": "1.5.3",
53
- "@httpcloak/linux-arm64": "1.5.3",
54
- "@httpcloak/darwin-x64": "1.5.3",
55
- "@httpcloak/darwin-arm64": "1.5.3",
56
- "@httpcloak/win32-x64": "1.5.3",
57
- "@httpcloak/win32-arm64": "1.5.3"
52
+ "@httpcloak/linux-x64": "1.5.4",
53
+ "@httpcloak/linux-arm64": "1.5.4",
54
+ "@httpcloak/darwin-x64": "1.5.4",
55
+ "@httpcloak/darwin-arm64": "1.5.4",
56
+ "@httpcloak/win32-x64": "1.5.4",
57
+ "@httpcloak/win32-arm64": "1.5.4"
58
58
  }
59
59
  }