@gjsify/http 0.4.36 → 0.4.38

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{EventEmitter as e}from"@gjsify/events";const t=`ACL.BIND.CHECKOUT.CONNECT.COPY.DELETE.GET.HEAD.LINK.LOCK.M-SEARCH.MERGE.MKACTIVITY.MKCALENDAR.MKCOL.MOVE.NOTIFY.OPTIONS.PATCH.POST.PROPFIND.PROPPATCH.PURGE.PUT.REBIND.REPORT.SEARCH.SOURCE.SUBSCRIBE.TRACE.UNBIND.UNLINK.UNLOCK.UNSUBSCRIBE`.split(`.`),n={100:`Continue`,101:`Switching Protocols`,102:`Processing`,103:`Early Hints`,200:`OK`,201:`Created`,202:`Accepted`,203:`Non-Authoritative Information`,204:`No Content`,205:`Reset Content`,206:`Partial Content`,207:`Multi-Status`,208:`Already Reported`,226:`IM Used`,300:`Multiple Choices`,301:`Moved Permanently`,302:`Found`,303:`See Other`,304:`Not Modified`,305:`Use Proxy`,307:`Temporary Redirect`,308:`Permanent Redirect`,400:`Bad Request`,401:`Unauthorized`,402:`Payment Required`,403:`Forbidden`,404:`Not Found`,405:`Method Not Allowed`,406:`Not Acceptable`,407:`Proxy Authentication Required`,408:`Request Timeout`,409:`Conflict`,410:`Gone`,411:`Length Required`,412:`Precondition Failed`,413:`Payload Too Large`,414:`URI Too Long`,415:`Unsupported Media Type`,416:`Range Not Satisfiable`,417:`Expectation Failed`,418:`I'm a Teapot`,421:`Misdirected Request`,422:`Unprocessable Entity`,423:`Locked`,424:`Failed Dependency`,425:`Too Early`,426:`Upgrade Required`,428:`Precondition Required`,429:`Too Many Requests`,431:`Request Header Fields Too Large`,451:`Unavailable For Legal Reasons`,500:`Internal Server Error`,501:`Not Implemented`,502:`Bad Gateway`,503:`Service Unavailable`,504:`Gateway Timeout`,505:`HTTP Version Not Supported`,506:`Variant Also Negotiates`,507:`Insufficient Storage`,508:`Loop Detected`,509:`Bandwidth Limit Exceeded`,510:`Not Extended`,511:`Network Authentication Required`},r=16384;var Agent=class extends e{maxSockets=1/0;maxFreeSockets=256;maxTotalSockets=1/0;sockets={};freeSockets={};requests={};destroy(){}};const i=new Agent;function urlToOptions(e){return{protocol:e.protocol,hostname:e.hostname,host:e.host,port:e.port,path:`${e.pathname}${e.search}`,auth:e.username||e.password?`${e.username}:${e.password}`:void 0}}function buildUrl(e){return`${e.protocol||`http:`}//${e.hostname||e.host||`localhost`}${e.port?`:${e.port}`:``}${e.path||`/`}`}var IncomingMessage=class extends e{statusCode;statusMessage;httpVersion=`1.1`;httpVersionMajor=1;httpVersionMinor=1;headers={};rawHeaders=[];trailers={};rawTrailers=[];url=``;method;readable=!0;destroyed=!1;complete=!1;constructor(e){super(),this.statusCode=e.status,this.statusMessage=e.statusText,e.headers.forEach((e,t)=>{this.headers[t.toLowerCase()]=e,this.rawHeaders.push(t,e)})}setEncoding(e){return this}pause(){return this}resume(){return this}destroy(e){return this.destroyed?this:(this.destroyed=!0,this.readable=!1,queueMicrotask(()=>{e&&this.emit(`error`,e),this.emit(`close`)}),this)}},ClientRequest=class extends e{method;path;_url;_headers;_bodyChunks=[];_started=!1;_ended=!1;_aborted=!1;_signal;_abortCtrl=new AbortController;_responseCb;socket=null;connection=null;writable=!0;destroyed=!1;constructor(e,t){if(super(),this.method=(e.method||`GET`).toUpperCase(),this.path=e.path||`/`,this._url=buildUrl(e),this._headers=e.headers?{...e.headers}:{},this._signal=e.signal,t&&(this._responseCb=t,this.once(`response`,t)),this._signal){let onAbort=()=>this.abort();this._signal.aborted?queueMicrotask(onAbort):this._signal.addEventListener(`abort`,onAbort,{once:!0})}}setHeader(e,t){return this._headers[e]=t,this}getHeader(e){return this._headers[e]}removeHeader(e){delete this._headers[e]}write(e,t,n){if(this._ended)return!1;let r=typeof t==`function`?t:n,i=typeof e==`string`?new TextEncoder().encode(e):e;return this._bodyChunks.push(i),r&&queueMicrotask(r),!0}end(e,t,n){if(this._ended)return this;e&&this.write(e,typeof t==`string`?t:void 0);let r=typeof t==`function`?t:n;return this._ended=!0,queueMicrotask(()=>this._flush(r)),this}abort(){this._aborted||(this._aborted=!0,this._abortCtrl.abort(),this.emit(`abort`))}destroy(e){return this.destroyed?this:(this.destroyed=!0,this._abortCtrl.abort(),e&&queueMicrotask(()=>this.emit(`error`,e)),this)}setTimeout(e,t){return t&&this.once(`timeout`,t),setTimeout(()=>this.emit(`timeout`),e),this}setNoDelay(e){}setSocketKeepAlive(e,t){}flushHeaders(){}async _flush(e){if(this._started)return;this._started=!0;let t=this._bodyChunks.length>0?new Blob(this._bodyChunks):void 0;try{let n=await fetch(this._url,{method:this.method,headers:this._normalizeHeaders(),body:t,signal:this._abortCtrl.signal,credentials:`same-origin`}),r=new IncomingMessage(n);this.emit(`response`,r),e&&queueMicrotask(e);let i=n.body?.getReader();if(!i){r.complete=!0,queueMicrotask(()=>r.emit(`end`));return}let pump=async()=>{try{for(;;){let{done:e,value:t}=await i.read();if(e)break;r.emit(`data`,t)}r.complete=!0,r.emit(`end`),r.emit(`close`)}catch(e){r.emit(`error`,e)}};pump()}catch(e){if(this._aborted)return;queueMicrotask(()=>this.emit(`error`,e))}}_normalizeHeaders(){let e={};for(let[t,n]of Object.entries(this._headers))e[t]=Array.isArray(n)?n.join(`, `):String(n);return e}};function request(e,t,n){let r,i;return typeof e==`string`||e instanceof URL?(r={...urlToOptions(typeof e==`string`?new URL(e):e),...typeof t==`object`?t:{}},i=typeof t==`function`?t:n):(r=e,i=typeof t==`function`?t:void 0),new ClientRequest(r,i)}function get(e,t,n){let r=request(e,t,n);return r.end(),r}function notSupported(e){let t=Error(`http.${e} is not supported in the browser`);throw t.code=`ENOTSUP`,t.errno=-45,t.syscall=e,t}var Server=class extends e{constructor(){super(),notSupported(`Server`)}},ServerResponse=class extends e{constructor(){super(),notSupported(`ServerResponse`)}},OutgoingMessage=class extends e{constructor(){super(),notSupported(`OutgoingMessage`)}};function createServer(...e){return notSupported(`createServer`)}function validateHeaderName(e){}function validateHeaderValue(e,t){}function setMaxIdleHTTPParsers(e){}const a={METHODS:t,STATUS_CODES:n,maxHeaderSize:r,Agent,globalAgent:i,IncomingMessage,ClientRequest,Server,ServerResponse,OutgoingMessage,createServer,request,get,validateHeaderName,validateHeaderValue,setMaxIdleHTTPParsers};export{Agent,ClientRequest,IncomingMessage,t as METHODS,OutgoingMessage,n as STATUS_CODES,Server,ServerResponse,createServer,a as default,get,i as globalAgent,r as maxHeaderSize,request,setMaxIdleHTTPParsers,validateHeaderName,validateHeaderValue};
1
+ import"./_virtual/_rolldown/runtime.js";import{EventEmitter as e}from"@gjsify/events";const t=`ACL.BIND.CHECKOUT.CONNECT.COPY.DELETE.GET.HEAD.LINK.LOCK.M-SEARCH.MERGE.MKACTIVITY.MKCALENDAR.MKCOL.MOVE.NOTIFY.OPTIONS.PATCH.POST.PROPFIND.PROPPATCH.PURGE.PUT.REBIND.REPORT.SEARCH.SOURCE.SUBSCRIBE.TRACE.UNBIND.UNLINK.UNLOCK.UNSUBSCRIBE`.split(`.`),n={100:`Continue`,101:`Switching Protocols`,102:`Processing`,103:`Early Hints`,200:`OK`,201:`Created`,202:`Accepted`,203:`Non-Authoritative Information`,204:`No Content`,205:`Reset Content`,206:`Partial Content`,207:`Multi-Status`,208:`Already Reported`,226:`IM Used`,300:`Multiple Choices`,301:`Moved Permanently`,302:`Found`,303:`See Other`,304:`Not Modified`,305:`Use Proxy`,307:`Temporary Redirect`,308:`Permanent Redirect`,400:`Bad Request`,401:`Unauthorized`,402:`Payment Required`,403:`Forbidden`,404:`Not Found`,405:`Method Not Allowed`,406:`Not Acceptable`,407:`Proxy Authentication Required`,408:`Request Timeout`,409:`Conflict`,410:`Gone`,411:`Length Required`,412:`Precondition Failed`,413:`Payload Too Large`,414:`URI Too Long`,415:`Unsupported Media Type`,416:`Range Not Satisfiable`,417:`Expectation Failed`,418:`I'm a Teapot`,421:`Misdirected Request`,422:`Unprocessable Entity`,423:`Locked`,424:`Failed Dependency`,425:`Too Early`,426:`Upgrade Required`,428:`Precondition Required`,429:`Too Many Requests`,431:`Request Header Fields Too Large`,451:`Unavailable For Legal Reasons`,500:`Internal Server Error`,501:`Not Implemented`,502:`Bad Gateway`,503:`Service Unavailable`,504:`Gateway Timeout`,505:`HTTP Version Not Supported`,506:`Variant Also Negotiates`,507:`Insufficient Storage`,508:`Loop Detected`,509:`Bandwidth Limit Exceeded`,510:`Not Extended`,511:`Network Authentication Required`},r=16384;var Agent=class extends e{maxSockets=1/0;maxFreeSockets=256;maxTotalSockets=1/0;sockets={};freeSockets={};requests={};destroy(){}};const i=new Agent;function urlToOptions(e){return{protocol:e.protocol,hostname:e.hostname,host:e.host,port:e.port,path:`${e.pathname}${e.search}`,auth:e.username||e.password?`${e.username}:${e.password}`:void 0}}function buildUrl(e){return`${e.protocol||`http:`}//${e.hostname||e.host||`localhost`}${e.port?`:${e.port}`:``}${e.path||`/`}`}var IncomingMessage=class extends e{statusCode;statusMessage;httpVersion=`1.1`;httpVersionMajor=1;httpVersionMinor=1;headers={};rawHeaders=[];trailers={};rawTrailers=[];url=``;method;readable=!0;destroyed=!1;complete=!1;aborted=!1;_buffer=[];_flowing=null;_paused=!1;_ended=!1;_decoder=null;constructor(e){super(),this.statusCode=e.status,this.statusMessage=e.statusText,e.headers.forEach((e,t)=>{this.headers[t.toLowerCase()]=e,this.rawHeaders.push(t,e)})}_push(e){if(e===null){if(this._decoder){let e=this._decoder.decode();e&&this._emitChunk(e)}this._ended=!0,this._maybeEnd();return}this._emitChunk(this._decoder?this._decoder.decode(e,{stream:!0}):e)}_emitChunk(e){this._flowing?this.emit(`data`,e):(this._buffer.push(e),this.emit(`readable`))}_maybeEnd(){this._ended&&this._buffer.length===0&&!this.complete&&(this.complete=!0,this.readable=!1,this.emit(`end`))}_drain(){for(;this._flowing&&!this._paused&&this._buffer.length>0;)this.emit(`data`,this._buffer.shift());this._maybeEnd()}setEncoding(e){return this._decoder=new TextDecoder(e===`binary`?`latin1`:e),this}read(){return this._buffer.length===0?null:this._buffer.shift()}pause(){return this._paused=!0,this._flowing=!1,this.emit(`pause`),this}resume(){return this._paused=!1,this._flowing=!0,queueMicrotask(()=>this._drain()),this.emit(`resume`),this}pipe(e){return this.on(`data`,t=>e.write(t)),this.on(`end`,()=>e.end()),this.resume(),e}on(e,t){return super.on(e,t),e===`data`&&this._flowing===null&&(this._flowing=!0,queueMicrotask(()=>this._drain())),this}destroy(e){return this.destroyed?this:(this.destroyed=!0,this.readable=!1,this.aborted=!0,queueMicrotask(()=>{e&&this.emit(`error`,e),this.emit(`close`)}),this)}async*[Symbol.asyncIterator](){let e=[],t=!1,n=null,r=null,onData=t=>{e.push(t),r?.()},onEnd=()=>{t=!0,r?.()},onError=e=>{n=e,r?.()};this.on(`data`,onData),this.once(`end`,onEnd),this.once(`error`,onError);try{for(;;){if(n)throw n;if(e.length>0){yield e.shift();continue}if(t)return;await new Promise(e=>{r=e})}}finally{this.removeListener(`data`,onData),this.removeListener(`end`,onEnd),this.removeListener(`error`,onError)}}},ClientRequest=class extends e{method;path;_url;_headers;_bodyChunks=[];_started=!1;_ended=!1;_aborted=!1;_signal;_abortCtrl=new AbortController;_responseCb;socket=null;connection=null;writable=!0;destroyed=!1;aborted=!1;constructor(e,t){if(super(),this.method=(e.method||`GET`).toUpperCase(),this.path=e.path||`/`,this._url=buildUrl(e),this._headers=e.headers?{...e.headers}:{},this._signal=e.signal,t&&(this._responseCb=t,this.once(`response`,t)),this._signal){let onAbort=()=>this.abort();this._signal.aborted?queueMicrotask(onAbort):this._signal.addEventListener(`abort`,onAbort,{once:!0})}}setHeader(e,t){return this._headers[e]=t,this}getHeader(e){return this._headers[e]}removeHeader(e){delete this._headers[e]}write(e,t,n){if(this._ended)return!1;let r=typeof t==`function`?t:n,i=typeof e==`string`?new TextEncoder().encode(e):e;return this._bodyChunks.push(i),r&&queueMicrotask(r),!0}end(e,t,n){if(this._ended)return this;e&&this.write(e,typeof t==`string`?t:void 0);let r=typeof t==`function`?t:n;return this._ended=!0,queueMicrotask(()=>this._flush(r)),this}abort(){this._aborted||(this._aborted=!0,this.aborted=!0,this.writable=!1,this._abortCtrl.abort(),queueMicrotask(()=>{this.emit(`abort`),this.emit(`close`)}))}destroy(e){return this.destroyed?this:(this.destroyed=!0,this._abortCtrl.abort(),e&&queueMicrotask(()=>this.emit(`error`,e)),this)}setTimeout(e,t){return t&&this.once(`timeout`,t),setTimeout(()=>this.emit(`timeout`),e),this}setNoDelay(e){}setSocketKeepAlive(e,t){}flushHeaders(){}async _flush(e){if(this._started)return;this._started=!0;let t=this._bodyChunks.length>0?new Blob(this._bodyChunks):void 0;try{let n=await fetch(this._url,{method:this.method,headers:this._normalizeHeaders(),body:t,signal:this._abortCtrl.signal,credentials:`same-origin`}),r=new IncomingMessage(n);r.method=this.method,r.url=this.path,this.emit(`response`,r),e&&queueMicrotask(e);let i=n.body?.getReader();if(!i){queueMicrotask(()=>r._push(null));return}let pump=async()=>{try{for(;;){let{done:e,value:t}=await i.read();if(e)break;r._push(t)}r._push(null)}catch(e){r.emit(`error`,e)}};pump()}catch(e){if(this._aborted)return;queueMicrotask(()=>this.emit(`error`,e))}}_normalizeHeaders(){let e={};for(let[t,n]of Object.entries(this._headers))e[t]=Array.isArray(n)?n.join(`, `):String(n);return e}};function request(e,t,n){let r,i;return typeof e==`string`||e instanceof URL?(r={...urlToOptions(typeof e==`string`?new URL(e):e),...typeof t==`object`?t:{}},i=typeof t==`function`?t:n):(r=e,i=typeof t==`function`?t:void 0),new ClientRequest(r,i)}function get(e,t,n){let r=request(e,t,n);return r.end(),r}function notSupported(e){let t=Error(`http.${e} is not supported in the browser`);throw t.code=`ENOTSUP`,t.errno=-45,t.syscall=e,t}var Server=class extends e{constructor(){super(),notSupported(`Server`)}},ServerResponse=class extends e{constructor(){super(),notSupported(`ServerResponse`)}},OutgoingMessage=class extends e{constructor(){super(),notSupported(`OutgoingMessage`)}};function createServer(...e){return notSupported(`createServer`)}function validateHeaderName(e){}function validateHeaderValue(e,t){}function setMaxIdleHTTPParsers(e){}const a={METHODS:t,STATUS_CODES:n,maxHeaderSize:r,Agent,globalAgent:i,IncomingMessage,ClientRequest,Server,ServerResponse,OutgoingMessage,createServer,request,get,validateHeaderName,validateHeaderValue,setMaxIdleHTTPParsers};export{Agent,ClientRequest,IncomingMessage,t as METHODS,OutgoingMessage,n as STATUS_CODES,Server,ServerResponse,createServer,a as default,get,i as globalAgent,r as maxHeaderSize,request,setMaxIdleHTTPParsers,validateHeaderName,validateHeaderValue};
@@ -45,11 +45,29 @@ export declare class IncomingMessage extends EventEmitter {
45
45
  readable: boolean;
46
46
  destroyed: boolean;
47
47
  complete: boolean;
48
+ aborted: boolean;
49
+ private _buffer;
50
+ private _flowing;
51
+ private _paused;
52
+ private _ended;
53
+ private _decoder;
48
54
  constructor(response: Response);
49
- setEncoding(_enc: string): this;
55
+ /** Feed one body chunk, or `null` to signal end-of-stream. */
56
+ _push(chunk: Uint8Array | null): void;
57
+ private _emitChunk;
58
+ private _maybeEnd;
59
+ private _drain;
60
+ setEncoding(enc: string): this;
61
+ read(): Uint8Array | string | null;
50
62
  pause(): this;
51
63
  resume(): this;
64
+ pipe<T extends {
65
+ write(c: unknown): unknown;
66
+ end(): unknown;
67
+ }>(dest: T): T;
68
+ on(event: string, listener: (...args: unknown[]) => void): this;
52
69
  destroy(err?: Error): this;
70
+ [Symbol.asyncIterator](): AsyncIterableIterator<Uint8Array | string>;
53
71
  }
54
72
  export declare class ClientRequest extends EventEmitter {
55
73
  method: string;
@@ -67,6 +85,7 @@ export declare class ClientRequest extends EventEmitter {
67
85
  connection: any;
68
86
  writable: boolean;
69
87
  destroyed: boolean;
88
+ aborted: boolean;
70
89
  constructor(options: RequestOptions, callback?: (res: IncomingMessage) => void);
71
90
  setHeader(name: string, value: string | string[]): this;
72
91
  getHeader(name: string): string | string[] | undefined;
@@ -93,6 +112,7 @@ export declare class ServerResponse extends EventEmitter {
93
112
  export declare class OutgoingMessage extends EventEmitter {
94
113
  constructor();
95
114
  }
115
+ /** Throws structured `ENOTSUP` — a browser cannot listen on a TCP socket. */
96
116
  export declare function createServer(..._args: unknown[]): Server;
97
117
  export declare function validateHeaderName(_name: string): void;
98
118
  export declare function validateHeaderValue(_name: string, _value: string): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/http",
3
- "version": "0.4.36",
3
+ "version": "0.4.38",
4
4
  "description": "Node.js http module for Gjs",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -31,6 +31,7 @@
31
31
  "build:test": "gjsify run build:test:gjs && gjsify run build:test:node",
32
32
  "build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
33
33
  "build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
34
+ "build:test:browser": "gjsify build src/test.browser.mts --app browser --outfile dist/test.browser.mjs",
34
35
  "test": "gjsify run build:gjsify && gjsify run build:test && gjsify run test:node && gjsify run test:gjs",
35
36
  "test:gjs": "gjsify run test.gjs.mjs",
36
37
  "test:node": "node test.node.mjs"
@@ -41,28 +42,29 @@
41
42
  "http"
42
43
  ],
43
44
  "devDependencies": {
44
- "@gjsify/cli": "^0.4.36",
45
- "@gjsify/unit": "^0.4.36",
45
+ "@gjsify/cli": "^0.4.38",
46
+ "@gjsify/unit": "^0.4.38",
46
47
  "@types/node": "^25.9.1",
47
- "typescript": "^5.9.3"
48
+ "typescript": "^6.0.3"
48
49
  },
49
50
  "dependencies": {
50
51
  "@girs/gio-2.0": "2.88.0-4.0.4",
51
52
  "@girs/glib-2.0": "2.88.0-4.0.4",
52
53
  "@girs/soup-3.0": "3.6.6-4.0.4",
53
- "@gjsify/buffer": "^0.4.36",
54
- "@gjsify/events": "^0.4.36",
55
- "@gjsify/http-soup-bridge": "^0.4.36",
56
- "@gjsify/net": "^0.4.36",
57
- "@gjsify/stream": "^0.4.36",
58
- "@gjsify/url": "^0.4.36",
59
- "@gjsify/utils": "^0.4.36"
54
+ "@gjsify/buffer": "^0.4.38",
55
+ "@gjsify/events": "^0.4.38",
56
+ "@gjsify/http-soup-bridge": "^0.4.38",
57
+ "@gjsify/net": "^0.4.38",
58
+ "@gjsify/stream": "^0.4.38",
59
+ "@gjsify/url": "^0.4.38",
60
+ "@gjsify/utils": "^0.4.38"
60
61
  },
61
62
  "gjsify": {
62
63
  "runtimes": {
63
64
  "gjs": "polyfill",
64
65
  "node": "none",
65
- "browser": "partial"
66
+ "browser": "partial",
67
+ "nativescript": "none"
66
68
  }
67
69
  },
68
70
  "license": "MIT",