From d4f0e1b9eeabb6f5652a247347dfc36226f47aaa Mon Sep 17 00:00:00 2001 From: Steven Edwards Date: Sat, 19 Jul 2025 15:42:10 -0400 Subject: [PATCH 1/2] Add support for headers --- ob-grpc.el | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ob-grpc.el b/ob-grpc.el index c6ea5b0..da21feb 100644 --- a/ob-grpc.el +++ b/ob-grpc.el @@ -146,6 +146,16 @@ in PROTO-FILE and IMPORT-PATHS. Else return methods under SERVICE." (nth 1 msg-template))))) +(defun ob-grpc--set-header-flag (header) + (concat "-H \"" header "\"")) + +(defun ob-grpc--headers-or-empty-string () + (let ((headers (org-entry-get nil "GRPC-HEADERS"))) + (if (eq nil headers) + "" + headers))) + + ;;;###autoload (defun org-babel-execute:grpc (body params) "Execute a grpc call with BODY as request, using grpcurl, with method and endpoint taken from PARAMS." @@ -153,12 +163,17 @@ in PROTO-FILE and IMPORT-PATHS. Else return methods under SERVICE." (import-paths (split-string (org-entry-get nil "PROTO-IMPORT-PATH" t) " ")) (grpc-endpoint (org-entry-get nil "GRPC-ENDPOINT" t)) (plain-text (org-entry-get nil "PLAIN-TEXT" t)) + (grpc-headers-list (split-string-and-unquote (ob-grpc--headers-or-empty-string))) + (grpc-headers (if (eq grpc-headers-list nil) + '() + grpc-headers-list)) (method (alist-get :method params))) (shell-command-to-string - (message "grpcurl %s -proto %s %s -d %s \"%s\" \"%s\"" + (message "grpcurl %s -proto %s %s %s -d %s \"%s\" \"%s\"" (ob-grpc--concat-imports import-paths) proto-file (if (equal plain-text "no") "" "-plaintext") + (mapconcat #'ob-grpc--set-header-flag grpc-headers " ") (prin1-to-string body) grpc-endpoint method From 1910b29bca0985ddceb35fb16448e33730bb438c Mon Sep 17 00:00:00 2001 From: Steven Edwards Date: Tue, 22 Jul 2025 16:19:51 -0400 Subject: [PATCH 2/2] Allow inherited GRPC-HEADERS --- ob-grpc.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ob-grpc.el b/ob-grpc.el index da21feb..b99f4b6 100644 --- a/ob-grpc.el +++ b/ob-grpc.el @@ -150,7 +150,7 @@ in PROTO-FILE and IMPORT-PATHS. Else return methods under SERVICE." (concat "-H \"" header "\"")) (defun ob-grpc--headers-or-empty-string () - (let ((headers (org-entry-get nil "GRPC-HEADERS"))) + (let ((headers (org-entry-get nil "GRPC-HEADERS" t))) (if (eq nil headers) "" headers)))