From 2fcaec4b21ebb85183310c58c4c2a731be81f4aa Mon Sep 17 00:00:00 2001 From: Alexander Scheel Date: Tue, 21 Mar 2023 18:37:17 -0400 Subject: [PATCH] Add support for HEAD operations (#19520) * Add header operation to sdk/logical Signed-off-by: Alexander Scheel * Add support for routing HEAD operations Signed-off-by: Alexander Scheel * Add changelog entry Signed-off-by: Alexander Scheel --------- Signed-off-by: Alexander Scheel --- changelog/19520.txt | 3 +++ http/logical.go | 6 ++++-- sdk/logical/request.go | 1 + sdk/logical/response_util.go | 2 +- sdk/logical/response_util_test.go | 8 ++++++++ 5 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 changelog/19520.txt diff --git a/changelog/19520.txt b/changelog/19520.txt new file mode 100644 index 000000000..726be2c13 --- /dev/null +++ b/changelog/19520.txt @@ -0,0 +1,3 @@ +```release-note:improvement +http: Support responding to HEAD operation from plugins +``` diff --git a/http/logical.go b/http/logical.go index 6da2e7dc7..8a681d910 100644 --- a/http/logical.go +++ b/http/logical.go @@ -183,8 +183,10 @@ func buildLogicalRequestNoAuth(perfStandby bool, w http.ResponseWriter, r *http. } data = parseQuery(r.URL.Query()) - - case "OPTIONS", "HEAD": + case "HEAD": + op = logical.HeaderOperation + data = parseQuery(r.URL.Query()) + case "OPTIONS": default: return nil, nil, http.StatusMethodNotAllowed, nil } diff --git a/sdk/logical/request.go b/sdk/logical/request.go index c50b7a031..2e54af1c0 100644 --- a/sdk/logical/request.go +++ b/sdk/logical/request.go @@ -369,6 +369,7 @@ const ( HelpOperation = "help" AliasLookaheadOperation = "alias-lookahead" ResolveRoleOperation = "resolve-role" + HeaderOperation = "header" // The operations below are called globally, the path is less relevant. RevokeOperation Operation = "revoke" diff --git a/sdk/logical/response_util.go b/sdk/logical/response_util.go index 42529eb78..6708871f4 100644 --- a/sdk/logical/response_util.go +++ b/sdk/logical/response_util.go @@ -20,7 +20,7 @@ import ( func RespondErrorCommon(req *Request, resp *Response, err error) (int, error) { if err == nil && (resp == nil || !resp.IsError()) { switch { - case req.Operation == ReadOperation: + case req.Operation == ReadOperation || req.Operation == HeaderOperation: if resp == nil { return http.StatusNotFound, nil } diff --git a/sdk/logical/response_util_test.go b/sdk/logical/response_util_test.go index d430b961e..eafaa2fc7 100644 --- a/sdk/logical/response_util_test.go +++ b/sdk/logical/response_util_test.go @@ -42,6 +42,14 @@ func TestResponseUtil_RespondErrorCommon_basic(t *testing.T) { respErr: nil, expectedStatus: 404, }, + { + title: "Header not found", + req: &Request{ + Operation: HeaderOperation, + }, + respErr: nil, + expectedStatus: 404, + }, { title: "List with response and no keys", req: &Request{