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{