mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
* init * WIP fix post data/refactor * make it compile again * more things * undo padding and continue + fix posting + update lshpack * re-add fixes * really simple tests + fixes * add aborted event * fix trailers * add getDefaultSettings, getPackedSettings and getUnpackedSettings * fix + fmt * fixes * fix enablePush o be boolean * fix sendTrailers * fmt * fix goaway, fix some error messages * oops * revert some changes * more reverts * WIP * get CMAKE building lspack + ping behavior * remove files that should not be added anymore * remove old out files * remove old file * fix header reduce * bunch of fixes * fix socket unref * fix abort signal, rebase and fmt * socket unref tests * oops re-add cmake * fix stream state * more tests and fixes * fixes and ping tests * lshpack in Dockerfile * just copy lshpack * oops * fix end * wantTrailers * encode/decode fixes + grpc * channel credentials test * rebase * support h2c * fix h2c * fix h2c connect event + h2c tests * 'copy ls-hpack * ls-hpack build sh * oops * changing CMake + Docker * add ps1 build for ls-hpack fix clean * optimizations + fixes * remove protect/unprotect from handlers * more consistent errors * fix error code * oops * add goaway tests * oops uncoment tests * better errors more tests * add broken priority frame * better memory leak, some fixes and less flask tests * zig update .Big -> .big * closer threshold + h2 fix * remove log * test should not be flask * increase timeout on leak memory test * windows build * less flasky * always 127.0.0.1 * [autofix.ci] apply automated fixes * remove .call and use primordials * apply socket fix * fix win-build * should properly mark inactive * postgres fix * increase deadline * test tests * high light deadline timeouts * event loop test * make memory leak test faster * use buffer on payload test * check for socket.data before use * reduce iterations to see if timeout on mac intel * fix assertions * avoid localhost and simplify things * refactor memory leak test * Update src/js/node/tls.js * fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: cirospaciari <ciro.spaciai@gmail.com> Co-authored-by: Jarred Sumner <jarred@jarredsumner.com> Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
83 lines
2.6 KiB
JavaScript
83 lines
2.6 KiB
JavaScript
const grpc = require("@grpc/grpc-js");
|
|
const loader = require("@grpc/proto-loader");
|
|
const { join } = require("path");
|
|
const { readFileSync } = require("fs");
|
|
|
|
const protoLoaderOptions = {
|
|
keepCase: true,
|
|
longs: String,
|
|
enums: String,
|
|
defaults: true,
|
|
oneofs: true,
|
|
};
|
|
|
|
function loadProtoFile(file) {
|
|
const packageDefinition = loader.loadSync(file, protoLoaderOptions);
|
|
return grpc.loadPackageDefinition(packageDefinition);
|
|
}
|
|
|
|
const protoFile = join(__dirname, "fixtures", "echo_service.proto");
|
|
const echoService = loadProtoFile(protoFile).EchoService;
|
|
|
|
const ca = readFileSync(join(__dirname, "fixtures", "ca.pem"));
|
|
const key = readFileSync(join(__dirname, "fixtures", "server1.key"));
|
|
const cert = readFileSync(join(__dirname, "fixtures", "server1.pem"));
|
|
|
|
const serviceImpl =
|
|
process.env.GRPC_SERVICE_TYPE === "1"
|
|
? {
|
|
echo: (call, callback) => {
|
|
const succeedOnRetryAttempt = call.metadata.get("succeed-on-retry-attempt");
|
|
const previousAttempts = call.metadata.get("grpc-previous-rpc-attempts");
|
|
if (
|
|
succeedOnRetryAttempt.length === 0 ||
|
|
(previousAttempts.length > 0 && previousAttempts[0] === succeedOnRetryAttempt[0])
|
|
) {
|
|
callback(null, call.request);
|
|
} else {
|
|
const statusCode = call.metadata.get("respond-with-status");
|
|
const code = statusCode[0] ? Number.parseInt(statusCode[0]) : grpc.status.UNKNOWN;
|
|
callback({
|
|
code: code,
|
|
details: `Failed on retry ${previousAttempts[0] ?? 0}`,
|
|
});
|
|
}
|
|
},
|
|
}
|
|
: {
|
|
echo: (call, callback) => {
|
|
if (call.metadata) {
|
|
call.sendMetadata(call.metadata);
|
|
}
|
|
callback(null, call.request);
|
|
},
|
|
};
|
|
|
|
function main() {
|
|
const options = process.env.GRPC_TEST_OPTIONS;
|
|
const server = options ? new grpc.Server(JSON.parse(options)) : new grpc.Server();
|
|
|
|
process.stdin.on("data", data => {
|
|
if (data.toString() === "shutdown") {
|
|
server.tryShutdown(() => {
|
|
process.exit(0);
|
|
});
|
|
}
|
|
});
|
|
server.addService(echoService.service, serviceImpl);
|
|
|
|
const useTLS = process.env.GRPC_TEST_USE_TLS === "true";
|
|
let credentials;
|
|
if (useTLS) {
|
|
credentials = grpc.ServerCredentials.createSsl(ca, [{ private_key: key, cert_chain: cert }]);
|
|
} else {
|
|
credentials = grpc.ServerCredentials.createInsecure();
|
|
}
|
|
server.bindAsync("127.0.0.1:0", credentials, () => {
|
|
server.start();
|
|
process.stdout.write(JSON.stringify(server.http2ServerList[0].server.address()));
|
|
});
|
|
}
|
|
|
|
main();
|