Skip to content

Commit

Permalink
switch to internal package, clean up url parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-willis committed Jan 21, 2025
1 parent a77d5d0 commit ba449e3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/insomnia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"fastq": "^1.17.1",
"graphql": "^16.8.1",
"graphql-ws": "^5.16.0",
"grpc-reflection-js": "ryanexus/grpc-reflection-js#path-prefix",
"grpc-reflection-js": "Kong/grpc-reflection-js#master",
"hawk": "9.0.2",
"hkdf": "^0.0.2",
"hosted-git-info": "5.2.1",
Expand Down
30 changes: 7 additions & 23 deletions packages/insomnia/src/network/grpc/parse-grpc-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,12 @@ export const parseGrpcUrl = (grpcUrl: string): { url: string; enableTls: boolean
if (!grpcUrl) {
return { url: '', enableTls: false, path: '' };
}
const lcUrl = grpcUrl.toLowerCase();
let url = {
protocol: 'grpc:',
hostname: lcUrl,
pathname: '',
port: undefined,
} as unknown as URL;
if (lcUrl.includes('://')) {
try {
url = new URL(grpcUrl.toLowerCase());
} catch (e) { }
}
const result = {
url: `${url.hostname}` + (url.port ? `:${url.port}` : ''),
enableTls: false,
path: url.pathname,
const url = new URL((grpcUrl.includes('://') ? '' : 'grpc://') + grpcUrl.toLowerCase());
return {
url: url.host,
enableTls: url.protocol === 'grpcs:',
// remove trailing slashes from pathname; the full request
// path is a concatenation of this parsed path + method path
path: url.pathname.endsWith('/') ? url.pathname.slice(0, -1) : url.pathname,
};
if (url.protocol.toLowerCase() === 'grpcs:') {
result.enableTls = true;
}
if (result.path === '/') {
result.path = '';
}
return result;
};

0 comments on commit ba449e3

Please sign in to comment.