@gjsify/http2 0.22.0 → 0.24.1
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
|
-
var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0}),t=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,__esmMin=(e,t)=>()=>(e&&(t=e(e=0)),t),__exportAll=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r},__copyProps=(i,a,o,s)=>{if(a&&typeof a==`object`||typeof a==`function`)for(var c=n(a),l=0,u=c.length,d;l<u;l++)d=c[l],!r.call(i,d)&&d!==o&&e(i,d,{get:(e=>a[e]).bind(null,d),enumerable:!(s=t(a,d))||s.enumerable});return i},__toCommonJS=t=>r.call(t,`module.exports`)?t[`module.exports`]:__copyProps(e({},`__esModule`,{value:!0}),t);export{__esmMin,__exportAll,__name,__toCommonJS};
|
|
1
|
+
var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0}),t=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,__esmMin=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},__exportAll=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r},__copyProps=(i,a,o,s)=>{if(a&&typeof a==`object`||typeof a==`function`)for(var c=n(a),l=0,u=c.length,d;l<u;l++)d=c[l],!r.call(i,d)&&d!==o&&e(i,d,{get:(e=>a[e]).bind(null,d),enumerable:!(s=t(a,d))||s.enumerable});return i},__toCommonJS=t=>r.call(t,`module.exports`)?t[`module.exports`]:__copyProps(e({},`__esModule`,{value:!0}),t);export{__esmMin,__exportAll,__name,__toCommonJS};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__toCommonJS as e}from"../_virtual/_rolldown/runtime.js";import{Http2ServerRequest as t}from"./request.js";import{Http2ServerResponse as n,ServerHttp2Stream as r}from"./response.js";import{ServerHttp2Session as i}from"./session.js";import{init_native_dispatcher as a,native_dispatcher_exports as o}from"../native-dispatcher.js";import s from"@girs/soup-3.0";import c from"@girs/gio-2.0";import l from"@girs/glib-2.0";import{EventEmitter as u}from"node:events";import{Buffer as d}from"node:buffer";import{deferEmit as f,ensureMainLoop as p}from"@gjsify/utils";const m=new Set;var Http2Server=class extends u{listening=!1;maxHeadersCount=2e3;timeout=0;_soupServer=null;_nativeDispatcher=null;_address=null;_options;get soupServer(){return this._soupServer}get nativeDispatcher(){return this._nativeDispatcher}constructor(e,t){super(),typeof e==`function`&&(t=e,e={}),this._options=e??{},t&&this.on(`request`,t)}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{let e=this._options.nativeDispatcher??`auto`,r=e===`force`||e===`auto`&&this._options.allowHTTP1===!1;if(e===`off`&&this._options.allowHTTP1===!1)throw Error(`createServer({ allowHTTP1: false }) requires the native dispatcher; nativeDispatcher cannot be "off" in this configuration`);if(r)return this._startNativeListen(t,n),p(),f(this,`listening`),m.add(this),this;this._soupServer=new s.Server({}),this._configureSoupServer(this._soupServer),this._soupServer.add_handler(null,(e,t,n)=>{this._handleRequest(t)}),this._soupServer.listen_local(t,s.ServerListenOptions.IPV4_ONLY),p();let i=this._soupServer.get_listeners(),a=t;if(i&&i.length>0){let e=i[0].get_local_address();e&&typeof e.get_port==`function`&&(a=e.get_port())}this.listening=!0,this._address={port:a,family:`IPv4`,address:n},m.add(this),f(this,`listening`)}catch(e){let t=e instanceof Error?e:Error(String(e));if(this.listenerCount(`error`)===0)throw t;f(this,`error`,t)}return this}_startNativeListen(t,n){let{Http2NativeDispatcher:r}=(a(),e(o));if(!r.available())throw Error(`@gjsify/http2-native prebuild is not loadable. createServer({ allowHTTP1: false }) requires the native HTTP/2 dispatcher. Ensure GjsifyHttp2-1.0.typelib is installed.`);this._nativeDispatcher=new r({handler:e=>this._handleNativeStream(e)});let i=this._nativeDispatcher.listen(t);this.listening=!0,this._address={port:i,family:`IPv4`,address:n}}_handleNativeStream(e){let a=new t,adapt=e=>({streamId:e.streamId,submitResponse:(t,n,r,i)=>{let a={":status":t};for(let[e,t]of r)a[e]=t;e.respond(a,i)},submitData:(t,n)=>e.writeData(t,n),reset:t=>e.reset(t),pushPromise:t=>{let n=e.pushPromise(t);return n?adapt(n):null}}),o=new n(null,adapt(e.backend)),s=new r(o,new i,{streamId:e.streamId});a._setStream(s),o._setStream(s);let c=e.headers;a.method=String(c[`:method`]??`GET`),a.url=String(c[`:path`]??`/`),a.authority=String(c[`:authority`]??``),a.scheme=String(c[`:scheme`]??`http`),a.httpVersion=`2.0`,a.httpVersionMajor=2,a.httpVersionMinor=0;for(let[e,t]of Object.entries(c))if(!e.startsWith(`:`))if(a.headers[e]=t,Array.isArray(t))for(let n of t)a.rawHeaders.push(e,n);else a.rawHeaders.push(e,t);a.socket={remoteAddress:e.remoteAddress,remotePort:e.remotePort,localAddress:this._address?.address??`127.0.0.1`,localPort:e.localPort,encrypted:!1},(async()=>{try{for await(let t of e.body)a._pushBody(t);a._pushBody(null)}catch{a._pushBody(null)}})();let l={...c};this.emit(`stream`,s,l),this.emit(`request`,a,o)}_configureSoupServer(e){}_handleRequest(e){let a=new t,o=new n(e);a.method=e.get_method();let l=e.get_uri(),u=l.get_path(),d=l.get_query();a.url=d?u+`?`+d:u,a.authority=l.get_host()??``,a.scheme=l.get_scheme()??`http`,e.get_http_version()===s.HTTPVersion.HTTP_2_0?(a.httpVersion=`2.0`,a.httpVersionMajor=2,a.httpVersionMinor=0):(a.httpVersion=`1.1`,a.httpVersionMajor=1,a.httpVersionMinor=1),e.get_request_headers().foreach((e,t)=>{let n=e.toLowerCase();if(a.rawHeaders.push(e,t),n in a.headers){let e=a.headers[n];Array.isArray(e)?e.push(t):a.headers[n]=[e,t]}else a.headers[n]=t});let f=e.get_remote_host()??`127.0.0.1`,p=e.get_remote_address();a.socket={remoteAddress:f,remotePort:p instanceof c.InetSocketAddress?p.get_port():0,localAddress:this._address?.address??`127.0.0.1`,localPort:this._address?.port??0,encrypted:this instanceof Http2SecureServer};let m=e.get_request_body();m?.data&&m.data.length>0?a._pushBody(m.data):a._pushBody(null);let h={":method":a.method,":path":a.url,":authority":a.authority,":scheme":a.scheme,...a.headers};e.pause(),o.on(`finish`,()=>e.unpause());let g=new r(o,new i);a._setStream(g),o._setStream(g),this.emit(`stream`,g,h),this.emit(`request`,a,o)}address(){return this._address}close(e){return e&&this.once(`close`,e),this._soupServer&&=(this._soupServer.disconnect(),null),this._nativeDispatcher&&=(this._nativeDispatcher.close(),null),this.listening=!1,m.delete(this),f(this,`close`),this}setTimeout(e,t){return this.timeout=e,t&&this.on(`timeout`,t),this}},Http2SecureServer=class extends Http2Server{_tlsCert=null;constructor(e,t){if(super(e,t),e.cert&&e.key){let t=_toPemString(e.cert),n=_toPemString(e.key);this._tlsCert=_createTlsCertificate(t,n)}else e.pfx}_configureSoupServer(e){this._tlsCert&&e.set_tls_certificate(this._tlsCert)}setSecureContext(e){if(e.cert&&e.key){let t=_toPemString(e.cert),n=_toPemString(e.key);this._tlsCert=_createTlsCertificate(t,n),this._soupServer&&this._tlsCert&&this._soupServer.set_tls_certificate(this._tlsCert)}}};function _toPemString(e){return Array.isArray(e)?e.map(_toPemString).join(`
|
|
1
|
+
import{__toCommonJS as e}from"../_virtual/_rolldown/runtime.js";import{Http2ServerRequest as t}from"./request.js";import{Http2ServerResponse as n,ServerHttp2Stream as r}from"./response.js";import{ServerHttp2Session as i}from"./session.js";import{init_native_dispatcher as a,native_dispatcher_exports as o}from"../native-dispatcher.js";import s from"@girs/soup-3.0";import c from"@girs/gio-2.0";import l from"@girs/glib-2.0";import{EventEmitter as u}from"node:events";import{Buffer as d}from"node:buffer";import{deferEmit as f,ensureMainLoop as p}from"@gjsify/utils/core";const m=new Set;var Http2Server=class extends u{listening=!1;maxHeadersCount=2e3;timeout=0;_soupServer=null;_nativeDispatcher=null;_address=null;_options;get soupServer(){return this._soupServer}get nativeDispatcher(){return this._nativeDispatcher}constructor(e,t){super(),typeof e==`function`&&(t=e,e={}),this._options=e??{},t&&this.on(`request`,t)}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{let e=this._options.nativeDispatcher??`auto`,r=e===`force`||e===`auto`&&this._options.allowHTTP1===!1;if(e===`off`&&this._options.allowHTTP1===!1)throw Error(`createServer({ allowHTTP1: false }) requires the native dispatcher; nativeDispatcher cannot be "off" in this configuration`);if(r)return this._startNativeListen(t,n),p(),f(this,`listening`),m.add(this),this;this._soupServer=new s.Server({}),this._configureSoupServer(this._soupServer),this._soupServer.add_handler(null,(e,t,n)=>{this._handleRequest(t)}),this._soupServer.listen_local(t,s.ServerListenOptions.IPV4_ONLY),p();let i=this._soupServer.get_listeners(),a=t;if(i&&i.length>0){let e=i[0].get_local_address();e&&typeof e.get_port==`function`&&(a=e.get_port())}this.listening=!0,this._address={port:a,family:`IPv4`,address:n},m.add(this),f(this,`listening`)}catch(e){let t=e instanceof Error?e:Error(String(e));if(this.listenerCount(`error`)===0)throw t;f(this,`error`,t)}return this}_startNativeListen(t,n){let{Http2NativeDispatcher:r}=(a(),e(o));if(!r.available())throw Error(`@gjsify/http2-native prebuild is not loadable. createServer({ allowHTTP1: false }) requires the native HTTP/2 dispatcher. Ensure GjsifyHttp2-1.0.typelib is installed.`);this._nativeDispatcher=new r({handler:e=>this._handleNativeStream(e)});let i=this._nativeDispatcher.listen(t);this.listening=!0,this._address={port:i,family:`IPv4`,address:n}}_handleNativeStream(e){let a=new t,adapt=e=>({streamId:e.streamId,submitResponse:(t,n,r,i)=>{let a={":status":t};for(let[e,t]of r)a[e]=t;e.respond(a,i)},submitData:(t,n)=>e.writeData(t,n),reset:t=>e.reset(t),pushPromise:t=>{let n=e.pushPromise(t);return n?adapt(n):null}}),o=new n(null,adapt(e.backend)),s=new r(o,new i,{streamId:e.streamId});a._setStream(s),o._setStream(s);let c=e.headers;a.method=String(c[`:method`]??`GET`),a.url=String(c[`:path`]??`/`),a.authority=String(c[`:authority`]??``),a.scheme=String(c[`:scheme`]??`http`),a.httpVersion=`2.0`,a.httpVersionMajor=2,a.httpVersionMinor=0;for(let[e,t]of Object.entries(c))if(!e.startsWith(`:`))if(a.headers[e]=t,Array.isArray(t))for(let n of t)a.rawHeaders.push(e,n);else a.rawHeaders.push(e,t);a.socket={remoteAddress:e.remoteAddress,remotePort:e.remotePort,localAddress:this._address?.address??`127.0.0.1`,localPort:e.localPort,encrypted:!1},(async()=>{try{for await(let t of e.body)a._pushBody(t);a._pushBody(null)}catch{a._pushBody(null)}})();let l={...c};this.emit(`stream`,s,l),this.emit(`request`,a,o)}_configureSoupServer(e){}_handleRequest(e){let a=new t,o=new n(e);a.method=e.get_method();let l=e.get_uri(),u=l.get_path(),d=l.get_query();a.url=d?u+`?`+d:u,a.authority=l.get_host()??``,a.scheme=l.get_scheme()??`http`,e.get_http_version()===s.HTTPVersion.HTTP_2_0?(a.httpVersion=`2.0`,a.httpVersionMajor=2,a.httpVersionMinor=0):(a.httpVersion=`1.1`,a.httpVersionMajor=1,a.httpVersionMinor=1),e.get_request_headers().foreach((e,t)=>{let n=e.toLowerCase();if(a.rawHeaders.push(e,t),n in a.headers){let e=a.headers[n];Array.isArray(e)?e.push(t):a.headers[n]=[e,t]}else a.headers[n]=t});let f=e.get_remote_host()??`127.0.0.1`,p=e.get_remote_address();a.socket={remoteAddress:f,remotePort:p instanceof c.InetSocketAddress?p.get_port():0,localAddress:this._address?.address??`127.0.0.1`,localPort:this._address?.port??0,encrypted:this instanceof Http2SecureServer};let m=e.get_request_body();m?.data&&m.data.length>0?a._pushBody(m.data):a._pushBody(null);let h={":method":a.method,":path":a.url,":authority":a.authority,":scheme":a.scheme,...a.headers};e.pause(),o.on(`finish`,()=>e.unpause());let g=new r(o,new i);a._setStream(g),o._setStream(g),this.emit(`stream`,g,h),this.emit(`request`,a,o)}address(){return this._address}close(e){return e&&this.once(`close`,e),this._soupServer&&=(this._soupServer.disconnect(),null),this._nativeDispatcher&&=(this._nativeDispatcher.close(),null),this.listening=!1,m.delete(this),f(this,`close`),this}setTimeout(e,t){return this.timeout=e,t&&this.on(`timeout`,t),this}},Http2SecureServer=class extends Http2Server{_tlsCert=null;constructor(e,t){if(super(e,t),e.cert&&e.key){let t=_toPemString(e.cert),n=_toPemString(e.key);this._tlsCert=_createTlsCertificate(t,n)}else e.pfx}_configureSoupServer(e){this._tlsCert&&e.set_tls_certificate(this._tlsCert)}setSecureContext(e){if(e.cert&&e.key){let t=_toPemString(e.cert),n=_toPemString(e.key);this._tlsCert=_createTlsCertificate(t,n),this._soupServer&&this._tlsCert&&this._soupServer.set_tls_certificate(this._tlsCert)}}};function _toPemString(e){return Array.isArray(e)?e.map(_toPemString).join(`
|
|
2
2
|
`):d.isBuffer(e)?e.toString(`utf8`):e}function _createTlsCertificate(e,t){let n=e.trimEnd()+`
|
|
3
3
|
`+t.trimEnd()+`
|
|
4
4
|
`;try{return c.TlsCertificate.new_from_pem(n,-1)}catch{let n=l.get_tmp_dir(),r=l.build_filenamev([n,`gjsify-http2-cert.pem`]),i=l.build_filenamev([n,`gjsify-http2-key.pem`]);try{return l.file_set_contents(r,e),l.file_set_contents(i,t),c.TlsCertificate.new_from_files(r,i)}finally{try{c.File.new_for_path(r).delete(null)}catch{}try{c.File.new_for_path(i).delete(null)}catch{}}}}export{Http2SecureServer,Http2Server};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/http2",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.1",
|
|
4
4
|
"description": "Node.js http2 module for Gjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"http2"
|
|
34
34
|
],
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@gjsify/cli": "^0.
|
|
37
|
-
"@gjsify/unit": "^0.
|
|
36
|
+
"@gjsify/cli": "^0.24.1",
|
|
37
|
+
"@gjsify/unit": "^0.24.1",
|
|
38
38
|
"@types/node": "^25.9.2",
|
|
39
39
|
"typescript": "^6.0.3"
|
|
40
40
|
},
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"@girs/glib-2.0": "^4.1.0",
|
|
44
44
|
"@girs/gobject-2.0": "^4.1.0",
|
|
45
45
|
"@girs/soup-3.0": "^4.1.0",
|
|
46
|
-
"@gjsify/events": "^0.
|
|
47
|
-
"@gjsify/http2-native": "^0.
|
|
48
|
-
"@gjsify/utils": "^0.
|
|
46
|
+
"@gjsify/events": "^0.24.1",
|
|
47
|
+
"@gjsify/http2-native": "^0.24.1",
|
|
48
|
+
"@gjsify/utils": "^0.24.1"
|
|
49
49
|
},
|
|
50
50
|
"gjsify": {
|
|
51
51
|
"runtimes": {
|