@gjsify/http 0.4.30 → 0.4.31

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.
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{IncomingMessage as e}from"./incoming-message.js";import{OutgoingMessage as t}from"./server.js";import n from"@girs/glib-2.0";import r from"@girs/soup-3.0";import i from"@girs/gio-2.0";import{Buffer as a}from"node:buffer";import{URL as o}from"node:url";import{readBytesAsync as s}from"@gjsify/utils";var ClientRequest=class extends t{method;path;protocol;host;hostname;port;aborted=!1;reusedSocket=!1;maxHeadersCount=2e3;_chunks=[];_session;_message;_cancellable;_timeout=0;_timeoutTimer=null;_responseCallback;constructor(e,t,s){super();let c;if(typeof e==`string`||e instanceof o){let n=typeof e==`string`?new o(e):e;c={protocol:n.protocol,hostname:n.hostname,port:n.port?Number(n.port):void 0,path:n.pathname+n.search,...typeof t==`object`?t:{}},typeof t==`function`&&(s=t)}else c=e,typeof t==`function`&&(s=t);if(this.method=(c.method||`GET`).toUpperCase(),this.protocol=c.protocol||`http:`,this.hostname=c.hostname||c.host?.split(`:`)[0]||`localhost`,this.port=Number(c.port)||(this.protocol===`https:`?443:80),this.path=c.path||`/`,this.host=c.host||`${this.hostname}:${this.port}`,this._timeout=c.timeout||0,s&&(this._responseCallback=s,this.once(`response`,s)),c.headers)for(let[e,t]of Object.entries(c.headers))this.setHeader(e,t);if(c.setHost!==!1&&!this._headers.has(`host`)){let e=this.protocol===`https:`?443:80,t=this.port===e?this.hostname:`${this.hostname}:${this.port}`;this.setHeader(`Host`,t)}c.auth&&!this._headers.has(`authorization`)&&this.setHeader(`Authorization`,`Basic `+a.from(c.auth).toString(`base64`)),c.signal&&(c.signal.aborted?this.abort():c.signal.addEventListener(`abort`,()=>this.abort(),{once:!0}));let l=n.Uri.parse(this._buildUrl(),n.UriFlags.NONE);this._session=new r.Session,this._message=new r.Message({method:this.method,uri:l}),this._cancellable=new i.Cancellable,this._timeout>0&&(this._session.timeout=Math.ceil(this._timeout/1e3),this._timeoutTimer=setTimeout(()=>{this._timeoutTimer=null,this.emit(`timeout`)},this._timeout))}_buildUrl(){let e=this.protocol.endsWith(`:`)?this.protocol:this.protocol+`:`,t=e===`https:`?443:80,n=this.port===t?``:`:${this.port}`;return`${e}//${this.hostname}${n}${this.path}`}getRawHeaderNames(){return Array.from(this._headers.keys())}flushHeaders(){this.headersSent||this._applyHeaders()}setTimeout(e,t){return this._timeout=e,this._timeoutTimer&&=(clearTimeout(this._timeoutTimer),null),t&&this.once(`timeout`,t),e>0&&(this._session.timeout=Math.ceil(e/1e3),this._timeoutTimer=setTimeout(()=>{this._timeoutTimer=null,this.emit(`timeout`)},e)),this}abort(){this.aborted||(this.aborted=!0,this._timeoutTimer&&=(clearTimeout(this._timeoutTimer),null),this._cancellable.cancel(),this.emit(`abort`),this.destroy())}_write(e,t,n){let r=a.isBuffer(e)?e:a.from(e,t);this._chunks.push(r),n()}_final(e){this._sendRequest().then(()=>e()).catch(t=>e(t))}_applyHeaders(){if(this.headersSent)return;this.headersSent=!0;let e=this._message.get_request_headers();for(let[t,n]of this._headers)if(Array.isArray(n))for(let r of n)e.append(t,r);else e.replace(t,n)}async _sendRequest(){this._applyHeaders();let t=a.concat(this._chunks);if(t.length>0){let e=this._headers.get(`content-type`)||`application/octet-stream`;this._message.set_request_body_from_bytes(e,new n.Bytes(t))}try{let t=await new Promise((e,t)=>{this._session.send_async(this._message,n.PRIORITY_DEFAULT,this._cancellable,(n,r)=>{try{e(this._session.send_finish(r))}catch(e){t(e)}})}),r=[];try{let e;for(;(e=await s(t,4096,n.PRIORITY_DEFAULT,this._cancellable))!==null;)r.push(a.from(e))}catch{}let i=new e;i.statusCode=this._message.status_code,i.statusMessage=this._message.get_reason_phrase(),i.httpVersion=`1.1`,this._message.get_response_headers().foreach((e,t)=>{let n=e.toLowerCase();if(i.rawHeaders.push(e,t),n in i.headers){let e=i.headers[n];Array.isArray(e)?e.push(t):i.headers[n]=[e,t]}else i.headers[n]=t}),this.finished=!0,this._timeoutTimer&&=(clearTimeout(this._timeoutTimer),null),this.emit(`response`,i),setTimeout(()=>{for(let e of r)i.push(e);i.push(null),i.complete=!0},0)}catch(e){this.aborted?this.emit(`abort`):this.emit(`error`,e instanceof Error?e:Error(String(e)))}}};export{ClientRequest};
1
+ import"./_virtual/_rolldown/runtime.js";import{IncomingMessage as e}from"./incoming-message.js";import{OutgoingMessage as t}from"./server.js";import n from"@girs/glib-2.0";import r from"@girs/soup-3.0";import i from"@girs/gio-2.0";import{Buffer as a}from"node:buffer";import{URL as o}from"node:url";import{readBytesAsync as s}from"@gjsify/utils";var ClientRequest=class extends t{method;path;protocol;host;hostname;port;aborted=!1;reusedSocket=!1;maxHeadersCount=2e3;_chunks=[];_session;_message;_cancellable;_timeout=0;_timeoutTimer=null;_responseCallback;constructor(e,t,s){super();let c;if(typeof e==`string`||e instanceof o){let n=typeof e==`string`?new o(e):e;c={protocol:n.protocol,hostname:n.hostname,port:n.port?Number(n.port):void 0,path:n.pathname+n.search,...typeof t==`object`?t:{}},typeof t==`function`&&(s=t)}else c=e,typeof t==`function`&&(s=t);if(this.method=(c.method||`GET`).toUpperCase(),this.protocol=c.protocol||`http:`,this.hostname=c.hostname||c.host?.split(`:`)[0]||`localhost`,this.port=Number(c.port)||(this.protocol===`https:`?443:80),this.path=c.path||`/`,this.host=c.host||`${this.hostname}:${this.port}`,this._timeout=c.timeout||0,s&&(this._responseCallback=s,this.once(`response`,s)),c.headers)for(let[e,t]of Object.entries(c.headers))this.setHeader(e,t);if(c.setHost!==!1&&!this._headers.has(`host`)){let e=this.protocol===`https:`?443:80,t=this.port===e?this.hostname:`${this.hostname}:${this.port}`;this.setHeader(`Host`,t)}c.auth&&!this._headers.has(`authorization`)&&this.setHeader(`Authorization`,`Basic `+a.from(c.auth).toString(`base64`)),c.signal&&(c.signal.aborted?this.abort():c.signal.addEventListener(`abort`,()=>this.abort(),{once:!0}));let l=n.Uri.parse(this._buildUrl(),n.UriFlags.NONE);this._session=new r.Session,this._message=new r.Message({method:this.method,uri:l}),this._cancellable=new i.Cancellable,this._timeout>0&&(this._session.timeout=Math.ceil(this._timeout/1e3),this._timeoutTimer=setTimeout(()=>{this._timeoutTimer=null,this.emit(`timeout`)},this._timeout))}_buildUrl(){let e=this.protocol.endsWith(`:`)?this.protocol:this.protocol+`:`,t=e===`https:`?443:80,n=this.port===t?``:`:${this.port}`;return`${e}//${this.hostname}${n}${this.path}`}getRawHeaderNames(){return Array.from(this._headers.keys())}flushHeaders(){this.headersSent||this._applyHeaders()}setTimeout(e,t){return this._timeout=e,this._timeoutTimer&&=(clearTimeout(this._timeoutTimer),null),t&&this.once(`timeout`,t),e>0&&(this._session.timeout=Math.ceil(e/1e3),this._timeoutTimer=setTimeout(()=>{this._timeoutTimer=null,this.emit(`timeout`)},e)),this}abort(){this.aborted||(this.aborted=!0,this._timeoutTimer&&=(clearTimeout(this._timeoutTimer),null),this._cancellable.cancel(),this.emit(`abort`),this.destroy())}_write(e,t,n){let r=a.isBuffer(e)?e:typeof e==`string`?a.from(e,t):a.from(e);this._chunks.push(r),n()}_final(e){this._sendRequest().then(()=>e()).catch(t=>e(t))}_applyHeaders(){if(this.headersSent)return;this.headersSent=!0;let e=this._message.get_request_headers();for(let[t,n]of this._headers)if(Array.isArray(n))for(let r of n)e.append(t,r);else e.replace(t,n)}async _sendRequest(){this._applyHeaders();let t=a.concat(this._chunks);if(t.length>0){let e=this._headers.get(`content-type`)||`application/octet-stream`;this._message.set_request_body_from_bytes(e,new n.Bytes(t))}try{let t=await new Promise((e,t)=>{this._session.send_async(this._message,n.PRIORITY_DEFAULT,this._cancellable,(n,r)=>{try{e(this._session.send_finish(r))}catch(e){t(e)}})}),r=[];try{let e;for(;(e=await s(t,4096,n.PRIORITY_DEFAULT,this._cancellable))!==null;)r.push(a.from(e))}catch{}let i=new e;i.statusCode=this._message.status_code,i.statusMessage=this._message.get_reason_phrase(),i.httpVersion=`1.1`,this._message.get_response_headers().foreach((e,t)=>{let n=e.toLowerCase();if(i.rawHeaders.push(e,t),n in i.headers){let e=i.headers[n];Array.isArray(e)?e.push(t):i.headers[n]=[e,t]}else i.headers[n]=t}),this.finished=!0,this._timeoutTimer&&=(clearTimeout(this._timeoutTimer),null),this.emit(`response`,i),setTimeout(()=>{for(let e of r)i.push(e);i.push(null),i.complete=!0},0)}catch(e){this.aborted?this.emit(`abort`):this.emit(`error`,e instanceof Error?e:Error(String(e)))}}};export{ClientRequest};
package/lib/esm/server.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{ServerRequestSocket as e}from"./server-request-socket.js";import{STATUS_CODES as t}from"./constants.js";import{IncomingMessage as n}from"./incoming-message.js";import{Buffer as r}from"node:buffer";import{createNodeError as i,deferEmit as a,ensureMainLoop as o}from"@gjsify/utils";import{EventEmitter as s}from"node:events";import{Writable as c}from"node:stream";import{Socket as l}from"@gjsify/net/socket";import{Server as u}from"@gjsify/http-soup-bridge";var OutgoingMessage=class extends c{headersSent=!1;sendDate=!0;finished=!1;socket=null;_headers=new Map;setHeader(e,t){return this._headers.set(e.toLowerCase(),typeof t==`number`?String(t):t),this}getHeader(e){return this._headers.get(e.toLowerCase())}removeHeader(e){this._headers.delete(e.toLowerCase())}hasHeader(e){return this._headers.has(e.toLowerCase())}getHeaderNames(){return Array.from(this._headers.keys())}getHeaders(){let e={};for(let[t,n]of this._headers)e[t]=n;return e}appendHeader(e,t){let n=e.toLowerCase(),r=this._headers.get(n);return r===void 0?this._headers.set(n,t):Array.isArray(r)?Array.isArray(t)?r.push(...t):r.push(t):Array.isArray(t)?this._headers.set(n,[r,...t]):this._headers.set(n,[r,t]),this}flushHeaders(){this.headersSent=!0}_write(e,t,n){n()}},ServerResponse=class extends OutgoingMessage{statusCode=200;statusMessage=``;_streaming=!1;_bridge;_timeoutTimer=null;constructor(e){super(),this._bridge=e,e.connect(`close`,()=>{this.emit(`close`)})}setTimeout(e,t){return this._timeoutTimer&&=(clearTimeout(this._timeoutTimer),null),t&&this.once(`timeout`,t),e>0&&(this._timeoutTimer=setTimeout(()=>{this._timeoutTimer=null,this.emit(`timeout`)},e)),this}writeHead(e,n,r){if(this.statusCode=e,typeof n==`object`&&(r=n,n=void 0),this.statusMessage=n||t[e]||``,r)for(let[e,t]of Object.entries(r))this.setHeader(e,t);return this}writeContinue(e){e&&Promise.resolve().then(e)}writeProcessing(e){e&&Promise.resolve().then(e)}flushHeaders(){this.headersSent||=!0}addTrailers(e){for(let[t,n]of Object.entries(e))this._headers.set(`trailer-`+t.toLowerCase(),n)}_startStreaming(){if(!this._streaming){this._streaming=!0,this.headersSent=!0,this._timeoutTimer&&=(clearTimeout(this._timeoutTimer),null);for(let[e,t]of this._headers)if(Array.isArray(t))for(let n of t)this._bridge.append_header(e,n);else this._bridge.set_header(e,t);this._bridge.write_head(this.statusCode,this.statusMessage||null)}}_write(e,t,n){let i=r.isBuffer(e)?e:r.from(e,t);this._startStreaming(),this._bridge.write_chunk(new Uint8Array(i.buffer,i.byteOffset,i.byteLength)),n()}_final(e){if(!this._streaming){for(let[e,t]of this._headers)if(Array.isArray(t))for(let n of t)this._bridge.append_header(e,n);else this._bridge.set_header(e,t);this._bridge.write_head(this.statusCode,this.statusMessage||null)}this._bridge.end(),this.finished=!0,e()}end(e,t,n){return typeof e==`function`?(n=e,e=void 0):typeof t==`function`&&(n=t,t=void 0),e!=null&&this.write(e,t),super.end(n),this}};const d=new Set;var Server=class extends s{listening=!1;maxHeadersCount=2e3;timeout=0;keepAliveTimeout=5e3;headersTimeout=6e4;requestTimeout=3e5;_bridge=null;_address=null;get soupServer(){return this._bridge?.soup_server??null}constructor(e,t){super();let n=typeof e==`function`?e:t;n&&this.on(`request`,n)}listen(...e){let t=0,n=`0.0.0.0`,r;for(let i of e)typeof i==`number`?t=i:typeof i==`string`?n=i:typeof i==`function`&&(r=i);r&&this.once(`listening`,r);try{this._bridge=new u,this._bridge.connect(`request-received`,(e,t,n)=>{this._handleRequest(t,n)}),this._bridge.connect(`upgrade`,(e,t,n,r)=>{this._handleUpgrade(t,n)}),this._bridge.connect(`error-occurred`,(e,t)=>{this.emit(`error`,Error(t))}),this._bridge.listen(t,n),o(),this.listening=!0,this._address={port:this._bridge.port,family:`IPv4`,address:this._bridge.address||n},d.add(this),a(this,`listening`)}catch(e){let r=i(e,`listen`,{address:n,port:t});a(this,`error`,r)}return this}_handleRequest(t,r){let i=new n,a=new ServerResponse(r);i.method=t.method,i.url=t.url,i.httpVersion=`1.1`;let o=t.header_pairs??[];for(let e=0;e+1<o.length;e+=2){let t=o[e],n=o[e+1],r=t.toLowerCase();if(i.rawHeaders.push(t,n),r in i.headers){let e=i.headers[r];Array.isArray(e)?e.push(n):i.headers[r]=[e,n]}else i.headers[r]=n}i.socket=new e(t.remote_address??`127.0.0.1`,t.remote_port??0,this._address?.address??`127.0.0.1`,this._address?.port??0,r);let s=t.get_body();s.length>0?i._pushBody(s):i._pushBody(null),t.connect(`aborted_signal`,()=>{i.aborted||(i.aborted=!0,i.emit(`aborted`))}),t.connect(`close`,()=>{i.emit(`close`)});try{let e=this.emit(`request`,i,a);(e instanceof Promise||typeof e==`object`&&e&&typeof e.then==`function`)&&e.catch(e=>{if(console.error(`[HTTP] Unhandled error in async request handler:`,e),!a.headersSent)try{a.writeHead(500),a.end(`Internal Server Error`)}catch{}})}catch(e){if(console.error(`[HTTP] Unhandled error in request handler:`,e),!a.headersSent)try{a.writeHead(500),a.end(`Internal Server Error`)}catch{}}}_handleUpgrade(e,t){let i=new n;i.method=e.method,i.url=e.url,i.httpVersion=`1.1`;let a=e.header_pairs??[];for(let e=0;e+1<a.length;e+=2){let t=a[e],n=a[e+1],r=t.toLowerCase();i.rawHeaders.push(t,n),i.headers[r]=n}if(this.listenerCount(`upgrade`)>0){let e=new l;e._attachOutputOnly(t),this.emit(`upgrade`,i,e,r.alloc(0))}}address(){return this._address}addWebSocketHandler(e,t){if(!this._bridge)throw Error(`Server must be listening before adding WebSocket handlers. Call listen() first.`);this._bridge.soup_server.add_websocket_handler(e,null,null,(e,n,r,i)=>{t(i)})}close(e){return e&&this.once(`close`,e),this._bridge&&=(this._bridge.close(),null),this.listening=!1,d.delete(this),a(this,`close`),this}setTimeout(e,t){return this.timeout=e,t&&this.on(`timeout`,t),this}};export{OutgoingMessage,Server,ServerResponse};
1
+ import"./_virtual/_rolldown/runtime.js";import{ServerRequestSocket as e}from"./server-request-socket.js";import{STATUS_CODES as t}from"./constants.js";import{IncomingMessage as n}from"./incoming-message.js";import{Buffer as r}from"node:buffer";import{createNodeError as i,deferEmit as a,ensureMainLoop as o}from"@gjsify/utils";import{EventEmitter as s}from"node:events";import{Writable as c}from"node:stream";import{Socket as l}from"@gjsify/net/socket";import{Server as u}from"@gjsify/http-soup-bridge";var OutgoingMessage=class extends c{headersSent=!1;sendDate=!0;finished=!1;socket=null;_headers=new Map;setHeader(e,t){return this._headers.set(e.toLowerCase(),typeof t==`number`?String(t):t),this}getHeader(e){return this._headers.get(e.toLowerCase())}removeHeader(e){this._headers.delete(e.toLowerCase())}hasHeader(e){return this._headers.has(e.toLowerCase())}getHeaderNames(){return Array.from(this._headers.keys())}getHeaders(){let e={};for(let[t,n]of this._headers)e[t]=n;return e}appendHeader(e,t){let n=e.toLowerCase(),r=this._headers.get(n);return r===void 0?this._headers.set(n,t):Array.isArray(r)?Array.isArray(t)?r.push(...t):r.push(t):Array.isArray(t)?this._headers.set(n,[r,...t]):this._headers.set(n,[r,t]),this}flushHeaders(){this.headersSent=!0}_write(e,t,n){n()}},ServerResponse=class extends OutgoingMessage{statusCode=200;statusMessage=``;_streaming=!1;_bridge;_timeoutTimer=null;constructor(e){super(),this._bridge=e,e.connect(`close`,()=>{this.emit(`close`)})}setTimeout(e,t){return this._timeoutTimer&&=(clearTimeout(this._timeoutTimer),null),t&&this.once(`timeout`,t),e>0&&(this._timeoutTimer=setTimeout(()=>{this._timeoutTimer=null,this.emit(`timeout`)},e)),this}writeHead(e,n,r){if(this.statusCode=e,typeof n==`object`&&(r=n,n=void 0),this.statusMessage=n||t[e]||``,r)for(let[e,t]of Object.entries(r))this.setHeader(e,t);return this}writeContinue(e){e&&Promise.resolve().then(e)}writeProcessing(e){e&&Promise.resolve().then(e)}flushHeaders(){this.headersSent||=!0}addTrailers(e){for(let[t,n]of Object.entries(e))this._headers.set(`trailer-`+t.toLowerCase(),n)}_startStreaming(){if(!this._streaming){this._streaming=!0,this.headersSent=!0,this._timeoutTimer&&=(clearTimeout(this._timeoutTimer),null);for(let[e,t]of this._headers)if(Array.isArray(t))for(let n of t)this._bridge.append_header(e,n);else this._bridge.set_header(e,t);this._bridge.write_head(this.statusCode,this.statusMessage||null)}}_write(e,t,n){let i=r.isBuffer(e)?e:typeof e==`string`?r.from(e,t):r.from(e);this._startStreaming(),this._bridge.write_chunk(new Uint8Array(i.buffer,i.byteOffset,i.byteLength)),n()}_final(e){if(!this._streaming){for(let[e,t]of this._headers)if(Array.isArray(t))for(let n of t)this._bridge.append_header(e,n);else this._bridge.set_header(e,t);this._bridge.write_head(this.statusCode,this.statusMessage||null)}this._bridge.end(),this.finished=!0,e()}end(e,t,n){return typeof e==`function`?(n=e,e=void 0):typeof t==`function`&&(n=t,t=void 0),e!=null&&this.write(e,t),super.end(n),this}};const d=new Set;var Server=class extends s{listening=!1;maxHeadersCount=2e3;timeout=0;keepAliveTimeout=5e3;headersTimeout=6e4;requestTimeout=3e5;_bridge=null;_address=null;get soupServer(){return this._bridge?.soup_server??null}constructor(e,t){super();let n=typeof e==`function`?e:t;n&&this.on(`request`,n)}listen(...e){let t=0,n=`0.0.0.0`,r;for(let i of e)typeof i==`number`?t=i:typeof i==`string`?n=i:typeof i==`function`&&(r=i);r&&this.once(`listening`,r);try{this._bridge=new u,this._bridge.connect(`request-received`,(e,t,n)=>{this._handleRequest(t,n)}),this._bridge.connect(`upgrade`,(e,t,n,r)=>{this._handleUpgrade(t,n)}),this._bridge.connect(`error-occurred`,(e,t)=>{this.emit(`error`,Error(t))}),this._bridge.listen(t,n),o(),this.listening=!0,this._address={port:this._bridge.port,family:`IPv4`,address:this._bridge.address||n},d.add(this),a(this,`listening`)}catch(e){let r=i(e,`listen`,{address:n,port:t});a(this,`error`,r)}return this}_handleRequest(t,r){let i=new n,a=new ServerResponse(r);i.method=t.method,i.url=t.url,i.httpVersion=`1.1`;let o=t.header_pairs??[];for(let e=0;e+1<o.length;e+=2){let t=o[e],n=o[e+1],r=t.toLowerCase();if(i.rawHeaders.push(t,n),r in i.headers){let e=i.headers[r];Array.isArray(e)?e.push(n):i.headers[r]=[e,n]}else i.headers[r]=n}i.socket=new e(t.remote_address??`127.0.0.1`,t.remote_port??0,this._address?.address??`127.0.0.1`,this._address?.port??0,r);let s=t.get_body();s.length>0?i._pushBody(s):i._pushBody(null),t.connect(`aborted_signal`,()=>{i.aborted||(i.aborted=!0,i.emit(`aborted`))}),t.connect(`close`,()=>{i.emit(`close`)});try{let e=this.emit(`request`,i,a);(e instanceof Promise||typeof e==`object`&&e&&typeof e.then==`function`)&&e.catch(e=>{if(console.error(`[HTTP] Unhandled error in async request handler:`,e),!a.headersSent)try{a.writeHead(500),a.end(`Internal Server Error`)}catch{}})}catch(e){if(console.error(`[HTTP] Unhandled error in request handler:`,e),!a.headersSent)try{a.writeHead(500),a.end(`Internal Server Error`)}catch{}}}_handleUpgrade(e,t){let i=new n;i.method=e.method,i.url=e.url,i.httpVersion=`1.1`;let a=e.header_pairs??[];for(let e=0;e+1<a.length;e+=2){let t=a[e],n=a[e+1],r=t.toLowerCase();i.rawHeaders.push(t,n),i.headers[r]=n}if(this.listenerCount(`upgrade`)>0){let e=new l;e._attachOutputOnly(t),this.emit(`upgrade`,i,e,r.alloc(0))}}address(){return this._address}addWebSocketHandler(e,t){if(!this._bridge)throw Error(`Server must be listening before adding WebSocket handlers. Call listen() first.`);this._bridge.soup_server.add_websocket_handler(e,null,null,(e,n,r,i)=>{t(i)})}close(e){return e&&this.once(`close`,e),this._bridge&&=(this._bridge.close(),null),this.listening=!1,d.delete(this),a(this,`close`),this}setTimeout(e,t){return this.timeout=e,t&&this.on(`timeout`,t),this}};export{OutgoingMessage,Server,ServerResponse};
@@ -1,6 +1,7 @@
1
1
  import { URL } from 'node:url';
2
2
  import { OutgoingMessage } from './server.js';
3
3
  import { IncomingMessage } from './incoming-message.js';
4
+ import type { Agent } from 'node:http';
4
5
  export interface ClientRequestOptions {
5
6
  protocol?: string;
6
7
  hostname?: string;
@@ -10,7 +11,7 @@ export interface ClientRequestOptions {
10
11
  method?: string;
11
12
  headers?: Record<string, string | number | string[]>;
12
13
  timeout?: number;
13
- agent?: any;
14
+ agent?: Agent | boolean;
14
15
  setHost?: boolean;
15
16
  /** Basic authentication string in the format 'user:password'. */
16
17
  auth?: string;
@@ -57,7 +58,7 @@ export declare class ClientRequest extends OutgoingMessage {
57
58
  /** Abort the request. */
58
59
  abort(): void;
59
60
  /** Writable stream _write implementation — collect body chunks. */
60
- _write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
61
+ _write(chunk: unknown, encoding: string, callback: (error?: Error | null) => void): void;
61
62
  /** Called when the writable stream ends — send the request. */
62
63
  _final(callback: (error?: Error | null) => void): void;
63
64
  private _applyHeaders;
@@ -4,6 +4,8 @@ declare module 'node:http' {
4
4
  keepAlive: boolean;
5
5
  keepAliveMsecs: number;
6
6
  scheduling: 'fifo' | 'lifo';
7
+ protocol: string;
8
+ maxFreeSockets: number;
7
9
  }
8
10
  }
9
11
  declare const _default: () => Promise<void>;
@@ -1,4 +1,5 @@
1
1
  import { Readable } from 'node:stream';
2
+ import type { Socket } from 'node:net';
2
3
  /**
3
4
  * IncomingMessage — Readable stream for HTTP request (server-side) or response (client-side).
4
5
  */
@@ -13,10 +14,10 @@ export declare class IncomingMessage extends Readable {
13
14
  statusCode?: number;
14
15
  statusMessage?: string;
15
16
  complete: boolean;
16
- socket: any;
17
+ socket: Socket | null;
17
18
  aborted: boolean;
18
19
  /** Node.js legacy alias for socket — needed by engine.io and other HTTP consumers. */
19
- get connection(): any;
20
+ get connection(): Socket;
20
21
  private _timeoutTimer;
21
22
  constructor();
22
23
  _read(_size: number): void;
@@ -29,7 +29,7 @@ export declare class OutgoingMessage extends Writable {
29
29
  appendHeader(name: string, value: string | string[]): this;
30
30
  /** Flush headers (no-op in base class). */
31
31
  flushHeaders(): void;
32
- _write(_chunk: any, _encoding: string, callback: (error?: Error | null) => void): void;
32
+ _write(_chunk: unknown, _encoding: string, callback: (error?: Error | null) => void): void;
33
33
  }
34
34
  /**
35
35
  * ServerResponse — Writable stream representing an HTTP response.
@@ -63,7 +63,7 @@ export declare class ServerResponse extends OutgoingMessage {
63
63
  */
64
64
  private _startStreaming;
65
65
  /** Writable stream _write — sends headers on first call, then appends each chunk. */
66
- _write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
66
+ _write(chunk: unknown, encoding: string, callback: (error?: Error | null) => void): void;
67
67
  /** Called by Writable.end() — finishes the bridge response. */
68
68
  _final(callback: (error?: Error | null) => void): void;
69
69
  /** Write status + headers + body in one call (convenience). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/http",
3
- "version": "0.4.30",
3
+ "version": "0.4.31",
4
4
  "description": "Node.js http module for Gjs",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -37,8 +37,8 @@
37
37
  "http"
38
38
  ],
39
39
  "devDependencies": {
40
- "@gjsify/cli": "^0.4.30",
41
- "@gjsify/unit": "^0.4.30",
40
+ "@gjsify/cli": "^0.4.31",
41
+ "@gjsify/unit": "^0.4.31",
42
42
  "@types/node": "^25.9.1",
43
43
  "typescript": "^6.0.3"
44
44
  },
@@ -46,12 +46,12 @@
46
46
  "@girs/gio-2.0": "2.88.0-4.0.1",
47
47
  "@girs/glib-2.0": "2.88.0-4.0.1",
48
48
  "@girs/soup-3.0": "3.6.6-4.0.1",
49
- "@gjsify/buffer": "^0.4.30",
50
- "@gjsify/events": "^0.4.30",
51
- "@gjsify/http-soup-bridge": "^0.4.30",
52
- "@gjsify/net": "^0.4.30",
53
- "@gjsify/stream": "^0.4.30",
54
- "@gjsify/url": "^0.4.30",
55
- "@gjsify/utils": "^0.4.30"
49
+ "@gjsify/buffer": "^0.4.31",
50
+ "@gjsify/events": "^0.4.31",
51
+ "@gjsify/http-soup-bridge": "^0.4.31",
52
+ "@gjsify/net": "^0.4.31",
53
+ "@gjsify/stream": "^0.4.31",
54
+ "@gjsify/url": "^0.4.31",
55
+ "@gjsify/utils": "^0.4.31"
56
56
  }
57
57
  }