@gjsify/http 0.53.0 → 0.55.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/lib/esm/browser.js +1 -1
- package/package.json +11 -11
package/lib/esm/browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{validateHeaderName as e,validateHeaderValue as t}from"./validators.js";import{EventEmitter as n}from"@gjsify/events";const r=`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(`.`),i={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`},a=16384;var Agent=class extends n{maxSockets=1/0;maxFreeSockets=256;maxTotalSockets=1/0;sockets={};freeSockets={};requests={};destroy(){}};const o=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 n{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(){if(this._buffer.length===0)return null;let e=this._buffer.shift();return this._buffer.length===0&&queueMicrotask(()=>this._maybeEnd()),e}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 n{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 n{constructor(){super(),notSupported(`Server`)}},ServerResponse=class extends n{constructor(){super(),notSupported(`ServerResponse`)}},OutgoingMessage=class extends n{constructor(){super(),notSupported(`OutgoingMessage`)}};function createServer(...e){return notSupported(`createServer`)}function setMaxIdleHTTPParsers(e){}const s={METHODS:r,STATUS_CODES:i,maxHeaderSize:a,Agent,globalAgent:o,IncomingMessage,ClientRequest,Server,ServerResponse,OutgoingMessage,createServer,request,get,validateHeaderName:e,validateHeaderValue:t,setMaxIdleHTTPParsers};export{Agent,ClientRequest,IncomingMessage,r as METHODS,OutgoingMessage,i as STATUS_CODES,Server,ServerResponse,createServer,s as default,get,o as globalAgent,a as maxHeaderSize,request,setMaxIdleHTTPParsers,e as validateHeaderName,t as validateHeaderValue};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{validateHeaderName as e,validateHeaderValue as t}from"./validators.js";import{EventEmitter as n}from"@gjsify/events";const r=`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(`.`),i={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`},a=16384;var Agent=class extends n{maxSockets=1/0;maxFreeSockets=256;maxTotalSockets=1/0;sockets={};freeSockets={};requests={};destroy(){}};const o=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 n{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(){if(this._buffer.length===0)return null;let e=this._buffer.shift();return this._buffer.length===0&&queueMicrotask(()=>this._maybeEnd()),e}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)}}};Object.defineProperty(IncomingMessage.prototype,"addListener",{...Object.getOwnPropertyDescriptor(IncomingMessage.prototype,`on`)});var ClientRequest=class extends n{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 n{constructor(){super(),notSupported(`Server`)}},ServerResponse=class extends n{constructor(){super(),notSupported(`ServerResponse`)}},OutgoingMessage=class extends n{constructor(){super(),notSupported(`OutgoingMessage`)}};function createServer(...e){return notSupported(`createServer`)}function setMaxIdleHTTPParsers(e){}const s={METHODS:r,STATUS_CODES:i,maxHeaderSize:a,Agent,globalAgent:o,IncomingMessage,ClientRequest,Server,ServerResponse,OutgoingMessage,createServer,request,get,validateHeaderName:e,validateHeaderValue:t,setMaxIdleHTTPParsers};export{Agent,ClientRequest,IncomingMessage,r as METHODS,OutgoingMessage,i as STATUS_CODES,Server,ServerResponse,createServer,s as default,get,o as globalAgent,a as maxHeaderSize,request,setMaxIdleHTTPParsers,e as validateHeaderName,t as validateHeaderValue};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.55.0",
|
|
4
4
|
"description": "Node.js http module for Gjs",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"http"
|
|
43
43
|
],
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@gjsify/cli": "^0.
|
|
46
|
-
"@gjsify/unit": "^0.
|
|
45
|
+
"@gjsify/cli": "^0.55.0",
|
|
46
|
+
"@gjsify/unit": "^0.55.0",
|
|
47
47
|
"@types/node": "^25.9.2",
|
|
48
48
|
"typescript": "^6.0.3"
|
|
49
49
|
},
|
|
@@ -51,14 +51,14 @@
|
|
|
51
51
|
"@girs/gio-2.0": "5.4.0",
|
|
52
52
|
"@girs/glib-2.0": "5.4.0",
|
|
53
53
|
"@girs/soup-3.0": "5.4.0",
|
|
54
|
-
"@gjsify/buffer": "^0.
|
|
55
|
-
"@gjsify/events": "^0.
|
|
56
|
-
"@gjsify/http-soup-bridge": "^0.
|
|
57
|
-
"@gjsify/net": "^0.
|
|
58
|
-
"@gjsify/stream": "^0.
|
|
59
|
-
"@gjsify/tls": "^0.
|
|
60
|
-
"@gjsify/url": "^0.
|
|
61
|
-
"@gjsify/utils": "^0.
|
|
54
|
+
"@gjsify/buffer": "^0.55.0",
|
|
55
|
+
"@gjsify/events": "^0.55.0",
|
|
56
|
+
"@gjsify/http-soup-bridge": "^0.55.0",
|
|
57
|
+
"@gjsify/net": "^0.55.0",
|
|
58
|
+
"@gjsify/stream": "^0.55.0",
|
|
59
|
+
"@gjsify/tls": "^0.55.0",
|
|
60
|
+
"@gjsify/url": "^0.55.0",
|
|
61
|
+
"@gjsify/utils": "^0.55.0"
|
|
62
62
|
},
|
|
63
63
|
"gjsify": {
|
|
64
64
|
"runtimes": {
|