@gjsify/https 0.52.0 → 0.53.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.
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # @gjsify/https
2
2
 
3
- GJS partial implementation of the Node.js `https` module. Provides Agent with stub request/get.
3
+ GJS partial implementation of the Node.js `https` module: `request`/`get` over Soup.Session, a stub
4
+ `Agent`, and `createServer`, whose server terminates TLS with the certificate you pass.
4
5
 
5
6
  Part of the [gjsify](https://github.com/gjsify/gjsify) project — Node.js and Web APIs for GJS (GNOME JavaScript).
6
7
 
@@ -22,6 +23,24 @@ import { Agent } from '@gjsify/https';
22
23
  const agent = new Agent({ keepAlive: true });
23
24
  ```
24
25
 
26
+ ### HTTPS server
27
+
28
+ ```typescript
29
+ import { createServer } from 'node:https';
30
+
31
+ const server = createServer({ key: keyPem, cert: certPem }, (req, res) => {
32
+ res.end('hello over TLS');
33
+ });
34
+ server.listen(8443);
35
+ ```
36
+
37
+ libsoup performs the handshake. `key`/`cert` take PEM strings or Buffers (a chain may follow the
38
+ leaf in `cert`). For client certificates, set `requestCert: true` and `ca` to the anchors they must
39
+ chain to; `rejectUnauthorized: false` lets unverified clients through, as on Node. Not yet
40
+ supported on GJS: `pfx`, an encrypted `key` with `passphrase`, and `SNICallback`. A `key` that does
41
+ not match its `cert` is not rejected at construction as it is on Node — libsoup only fails the
42
+ handshake. Without a certificate `listen()` emits `'error'` instead of serving plain text.
43
+
25
44
  ## License
26
45
 
27
46
  MIT
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{Server as e,get as t,request as n}from"node:http";import{TLSSocket as r,createSecureContext as i}from"node:tls";import{URL as a}from"node:url";var Agent=class{defaultPort=443;protocol=`https:`;maxSockets=1/0;maxFreeSockets=256;constructor(e){}destroy(){}};const o=new Agent;function request(e,t,r){if(typeof e==`string`){if(e.startsWith(`https://`)||e.startsWith(`http://`))return n(e,t,r);let i={hostname:e,protocol:`https:`,port:443};return typeof t==`object`&&Object.assign(i,t),typeof t==`function`&&(r=t),n(i,r)}if(e instanceof a)return n(e,t,r);let i={protocol:`https:`,port:443,...e};return typeof t==`function`&&(r=t),n(i,r)}function get(e,n,r){if(typeof e==`string`){if(e.startsWith(`https://`)||e.startsWith(`http://`))return t(e,n,r);let i={hostname:e,protocol:`https:`,port:443};return typeof n==`object`&&Object.assign(i,n),typeof n==`function`&&(r=n),t(i,r)}if(e instanceof a)return t(e,n,r);let i={protocol:`https:`,port:443,...e,method:`GET`};return typeof n==`function`&&(r=n),t(i,r)}var Server=class extends e{constructor(e,t){super(t)}};function createServer(e,t){return typeof e==`function`?new Server(void 0,e):new Server(e,t)}var s={Agent,globalAgent:o,Server,request,get,createServer,TLSSocket:r,createSecureContext:i};export{Agent,Server,r as TLSSocket,i as createSecureContext,createServer,s as default,get,o as globalAgent,request};
1
+ import"./_virtual/_rolldown/runtime.js";import{Agent as e,Server as t,request as n}from"node:http";import{TLSSocket as r,createSecureContext as i}from"node:tls";import{URL as a}from"node:url";var Agent=class extends e{defaultPort=443;protocol=`https:`;constructor(e){super(e)}};const o=new Agent;function withDefaultAgent(e){return{...e,_defaultAgent:o}}function request(e,t,r){return typeof t==`function`&&(r=t,t=void 0),typeof e==`string`?e.startsWith(`https://`)||e.startsWith(`http://`)?n(e,withDefaultAgent(t),r):n(withDefaultAgent({hostname:e,protocol:`https:`,port:443,...t}),r):e instanceof a?n(e,withDefaultAgent(t),r):n(withDefaultAgent({protocol:`https:`,port:443,...e,...t}),r)}function get(e,t,n){let r=request(e,t,n);return r.end(),r}var Server=class extends t{constructor(e,t){let n=typeof e==`function`?{}:e??{};super(typeof e==`function`?e:t),this._useTls(n)}};function createServer(e,t){return typeof e==`function`?new Server(e):new Server(e,t)}var s={Agent,globalAgent:o,Server,request,get,createServer,TLSSocket:r,createSecureContext:i};export{Agent,Server,r as TLSSocket,i as createSecureContext,createServer,s as default,get,o as globalAgent,request};
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
@@ -1,6 +1,6 @@
1
- import type { ClientRequest, IncomingMessage } from 'node:http';
2
- import { Server as HttpServer } from 'node:http';
3
- import { TLSSocket, createSecureContext } from 'node:tls';
1
+ import type { ClientRequest, IncomingMessage, ServerResponse } from 'node:http';
2
+ import { Server as HttpServer, Agent as HttpAgent, type AgentOptions as HttpAgentOptions } from 'node:http';
3
+ import { TLSSocket, createSecureContext, type PeerCertificate, type SecureContext } from 'node:tls';
4
4
  import { URL } from 'node:url';
5
5
  export { TLSSocket, createSecureContext };
6
6
  export interface RequestOptions {
@@ -17,18 +17,21 @@ export interface RequestOptions {
17
17
  ca?: string | Buffer | Array<string | Buffer>;
18
18
  cert?: string | Buffer | Array<string | Buffer>;
19
19
  key?: string | Buffer | Array<string | Buffer>;
20
+ passphrase?: string;
20
21
  rejectUnauthorized?: boolean;
22
+ servername?: string;
23
+ checkServerIdentity?: (host: string, cert: PeerCertificate) => Error | undefined;
24
+ secureContext?: SecureContext;
21
25
  }
26
+ export type AgentOptions = HttpAgentOptions & Pick<RequestOptions, 'ca' | 'cert' | 'key' | 'passphrase' | 'rejectUnauthorized' | 'servername' | 'checkServerIdentity' | 'secureContext'>;
22
27
  /**
23
- * HTTPS Agent for connection pooling (stub — Soup.Session handles TLS internally).
28
+ * HTTPS Agent. Pooling is Soup.Session's; what the agent contributes is its TLS options
29
+ * (`ca`, `cert`/`key`, `rejectUnauthorized`, …), which override each request's, as in Node.
24
30
  */
25
- export declare class Agent {
31
+ export declare class Agent extends HttpAgent {
26
32
  defaultPort: number;
27
33
  protocol: string;
28
- maxSockets: number;
29
- maxFreeSockets: number;
30
- constructor(_options?: Record<string, unknown>);
31
- destroy(): void;
34
+ constructor(options?: AgentOptions);
32
35
  }
33
36
  export declare const globalAgent: Agent;
34
37
  /**
@@ -43,22 +46,21 @@ export declare function get(url: string | URL | RequestOptions, options?: Reques
43
46
  export interface HttpsServerOptions extends RequestOptions {
44
47
  requestCert?: boolean;
45
48
  }
49
+ type HttpsRequestListener = (req: IncomingMessage, res: ServerResponse) => void;
46
50
  /**
47
- * HTTPS Server — wraps TLS server with HTTP request handling.
48
- * Uses tls.createServer for the TLS layer and processes HTTP
49
- * requests on top.
51
+ * HTTPS Server — an http.Server whose listener terminates TLS with `options.key`/`options.cert`.
52
+ * Reference: Node.js lib/https.js. The Gio side (certificate, client-certificate verification,
53
+ * the HTTPS listener) lives in @gjsify/http, so this package stays a layer over `node:http`.
50
54
  */
51
55
  export declare class Server extends HttpServer {
52
- constructor(options?: HttpsServerOptions, requestListener?: (req: IncomingMessage, res: unknown) => void);
56
+ constructor(options?: HttpsServerOptions, requestListener?: HttpsRequestListener);
57
+ constructor(requestListener?: HttpsRequestListener);
53
58
  }
54
59
  /**
55
- * Create an HTTPS server.
56
- * In GJS, Soup.Server can handle HTTPS natively if configured with
57
- * a TLS certificate. For API compatibility, this wraps the TLS server
58
- * infrastructure.
60
+ * Create an HTTPS server that presents `options.key`/`options.cert`.
59
61
  */
60
- export declare function createServer(options?: HttpsServerOptions, requestListener?: (req: IncomingMessage, res: unknown) => void): Server;
61
- export declare function createServer(requestListener?: (req: IncomingMessage, res: unknown) => void): Server;
62
+ export declare function createServer(options?: HttpsServerOptions, requestListener?: HttpsRequestListener): Server;
63
+ export declare function createServer(requestListener?: HttpsRequestListener): Server;
62
64
  declare const _default: {
63
65
  Agent: typeof Agent;
64
66
  globalAgent: Agent;
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/https",
3
- "version": "0.52.0",
3
+ "version": "0.53.0",
4
4
  "description": "Node.js https module for Gjs",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
@@ -40,14 +40,15 @@
40
40
  "https"
41
41
  ],
42
42
  "devDependencies": {
43
- "@gjsify/cli": "^0.52.0",
44
- "@gjsify/unit": "^0.52.0",
43
+ "@gjsify/cli": "^0.53.0",
44
+ "@gjsify/runtime": "^0.53.0",
45
+ "@gjsify/unit": "^0.53.0",
45
46
  "@types/node": "^25.9.2",
46
47
  "typescript": "^6.0.3"
47
48
  },
48
49
  "dependencies": {
49
- "@gjsify/http": "^0.52.0",
50
- "@gjsify/tls": "^0.52.0"
50
+ "@gjsify/http": "^0.53.0",
51
+ "@gjsify/tls": "^0.53.0"
51
52
  },
52
53
  "gjsify": {
53
54
  "runtimes": {