Skip to content

Commit

Permalink
use path prefix for gRPC conns
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-willis committed Jan 9, 2025
1 parent 79bb6db commit 02b5d25
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
11 changes: 6 additions & 5 deletions packages/insomnia/src/main/ipc/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export const start = (
}
const methodType = getMethodType(method);
// Create client
const { url } = parseGrpcUrl(request.url);
const { url, path } = parseGrpcUrl(request.url);

if (!url) {
event.reply('grpc.error', request._id, new Error('URL not specified'));
Expand All @@ -405,10 +405,11 @@ export const start = (

try {
const messageBody = JSON.parse(request.body.text || '');
const requestPath = path + method.path;
switch (methodType) {
case 'unary':
const unaryCall = client.makeUnaryRequest(
method.path,
requestPath,
method.requestSerialize,
method.responseDeserialize,
messageBody,
Expand All @@ -420,7 +421,7 @@ export const start = (
break;
case 'client':
const clientCall = client.makeClientStreamRequest(
method.path,
requestPath,
method.requestSerialize,
method.responseDeserialize,
filterDisabledMetaData(request.metadata),
Expand All @@ -430,7 +431,7 @@ export const start = (
break;
case 'server':
const serverCall = client.makeServerStreamRequest(
method.path,
requestPath,
method.requestSerialize,
method.responseDeserialize,
messageBody,
Expand All @@ -441,7 +442,7 @@ export const start = (
break;
case 'bidi':
const bidiCall = client.makeBidiStreamRequest(
method.path,
requestPath,
method.requestSerialize,
method.responseDeserialize,
filterDisabledMetaData(request.metadata));
Expand Down
21 changes: 13 additions & 8 deletions packages/insomnia/src/network/grpc/parse-grpc-url.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
export const parseGrpcUrl = (grpcUrl: string): { url: string; enableTls: boolean } => {
export const parseGrpcUrl = (grpcUrl: string): { url: string; enableTls: boolean; path: string } => {
if (!grpcUrl) {
return { url: '', enableTls: false };
return { url: '', enableTls: false, path: '' };
}
const lower = grpcUrl.toLowerCase();
if (lower.startsWith('grpc://')) {
return { url: lower.slice(7), enableTls: false };
const url = new URL(grpcUrl);
const result = {
url: url.host,
enableTls: false,
path: url.pathname,
};
if (url.protocol === 'grpcs:') {
result.enableTls = true;
}
if (lower.startsWith('grpcs://')) {
return { url: lower.slice(8), enableTls: true };
if (result.path === '/') {
result.path = '';
}
return { url: lower, enableTls: false };
return result;
};
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export const GrpcMethodDropdown: FunctionComponent<Props> = ({
}));
const selectedPath = selectedMethod?.fullPath;

console.log(methods, disabled);
return (
<Select
aria-label="Select gRPC method"
Expand Down

0 comments on commit 02b5d25

Please sign in to comment.