astro-ghostcms/.pnpm-store/v3/files/11/4edc5c410e87941ca11ed7e2fc9...

41 lines
1.0 KiB
Plaintext
Raw Normal View History

2024-02-14 14:10:47 +00:00
'use strict';
const {Agent} = require('../agent.js');
const JSStreamSocket = require('../utils/js-stream-socket.js');
const UnexpectedStatusCodeError = require('./unexpected-status-code-error.js');
const initialize = require('./initialize.js');
class Http2OverHttpX extends Agent {
constructor(options) {
super(options);
initialize(this, options.proxyOptions);
}
async createConnection(origin, options) {
const authority = `${origin.hostname}:${origin.port || 443}`;
const [stream, statusCode, statusMessage] = await this._getProxyStream(authority);
if (statusCode !== 200) {
throw new UnexpectedStatusCodeError(statusCode, statusMessage);
}
if (this.proxyOptions.raw) {
options.socket = stream;
} else {
const socket = new JSStreamSocket(stream);
socket.encrypted = false;
socket._handle.getpeername = out => {
out.family = undefined;
out.address = undefined;
out.port = undefined;
};
return socket;
}
return super.createConnection(origin, options);
}
}
module.exports = Http2OverHttpX;