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

feat: add headers to grpcurl command #248

Merged
merged 2 commits into from
Jun 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions internal/resources/webform/webform.js
Original file line number Diff line number Diff line change
Expand Up @@ -2105,7 +2105,22 @@ window.initGRPCForm = function(services, svcDescs, mtdDescs, invokeURI, metadata
function updateCurlCommand(requestDataJson) {
let service = $("#grpc-service").val();
let method = $("#grpc-method").val();
gRPCurlTextArea.html(`<div>grpcurl -plaintext -d '${requestDataJson}' ${window.target} ${service}.${method}</div>`);

var metadataStr = "";
var rows = $("#grpc-request-metadata-form tr");
for (var i = 0; i < rows.length; i++) {
var cells = $("input", rows[i]);
if (cells.length === 0) {
continue;
}
var name = $(cells[0]).val();
var val = $(cells[1]).val();
if (name !== "") {
metadataStr += ` -H "${name}: ${val}"`;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I noticed, changing keys/values/rows in the headers doesn't trigger updateCurlCommand. I'm not sure if it's worth the level of invasiveness that would require tho. Thoughts?

Maybe we could always just force a re-render when the Raw Request tab is shown instead of the crazy stuff we're currently doing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, I noticed a bug where on first render, if you load the app (or change the selected method) and click on the raw request tab, the curl command contains an [object Object] instead of {}.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I agree with you. For example, the updateCurlCommand func receives the entire request instead just the body. I believe this would involve a larger PR of refactoring. But for now, due to lack of time, I can't do that. Merging this PR would help people here a lot.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough


gRPCurlTextArea.html(`<div>grpcurl -plaintext${metadataStr} -d '${requestDataJson}' ${window.target} ${service}.${method}</div>`);
}

var jsonRawTextArea = $("#grpc-request-raw-text");
Expand Down Expand Up @@ -2776,7 +2791,7 @@ window.initGRPCForm = function(services, svcDescs, mtdDescs, invokeURI, metadata
validateJSON();
// remove all rows
$("tr").remove('.metadataRow');
// item.request.metadata will be undefined when using -examples
// item.request.metadata will be undefined when using -examples
// and without setting in json file, here it needs to be verified
if (item.request.metadata) {
for (let metadata of item.request.metadata) {
Expand Down