Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give Callers the Ability to set TCP_NODELAY #223

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/twirpscript/src/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { RpcTransport } from "../index.js";
import {
RpcTransportOpts,
RpcTransportResponse,
} from "../runtime/client/index.js";
import * as http from "http";
import * as https from "https";

export const nodeHttpTransport: RpcTransport = (url, options) => {
export const nodeHttpTransport: RpcTransport = (
url: string,
options: RpcTransportOpts,
): Promise<RpcTransportResponse> => {
const request = url.startsWith("https") ? https.request : http.request;
return new Promise((resolve, reject) => {
const chunks: Buffer[] = [];
Expand Down Expand Up @@ -32,6 +39,10 @@ export const nodeHttpTransport: RpcTransport = (url, options) => {
},
).on("error", reject);

if (options.noDelay) {
req.setNoDelay(true);
}

req.end(
options.body instanceof Uint8Array
? Buffer.from(options.body)
Expand Down
1 change: 1 addition & 0 deletions packages/twirpscript/src/runtime/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export interface RpcTransportOpts {
method: string;
headers: Record<string, string>;
body: string | Uint8Array | undefined | null;
noDelay?: boolean;
}

/**
Expand Down