Add support for HEAD operations (#19520)

* Add header operation to sdk/logical

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add support for routing HEAD operations

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

* Add changelog entry

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>

---------

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
This commit is contained in:
Alexander Scheel 2023-03-21 18:37:17 -04:00 committed by GitHub
parent 89fa73c9f7
commit 2fcaec4b21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 3 deletions

3
changelog/19520.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
http: Support responding to HEAD operation from plugins
```

View File

@ -183,8 +183,10 @@ func buildLogicalRequestNoAuth(perfStandby bool, w http.ResponseWriter, r *http.
} }
data = parseQuery(r.URL.Query()) data = parseQuery(r.URL.Query())
case "HEAD":
case "OPTIONS", "HEAD": op = logical.HeaderOperation
data = parseQuery(r.URL.Query())
case "OPTIONS":
default: default:
return nil, nil, http.StatusMethodNotAllowed, nil return nil, nil, http.StatusMethodNotAllowed, nil
} }

View File

@ -369,6 +369,7 @@ const (
HelpOperation = "help" HelpOperation = "help"
AliasLookaheadOperation = "alias-lookahead" AliasLookaheadOperation = "alias-lookahead"
ResolveRoleOperation = "resolve-role" ResolveRoleOperation = "resolve-role"
HeaderOperation = "header"
// The operations below are called globally, the path is less relevant. // The operations below are called globally, the path is less relevant.
RevokeOperation Operation = "revoke" RevokeOperation Operation = "revoke"

View File

@ -20,7 +20,7 @@ import (
func RespondErrorCommon(req *Request, resp *Response, err error) (int, error) { func RespondErrorCommon(req *Request, resp *Response, err error) (int, error) {
if err == nil && (resp == nil || !resp.IsError()) { if err == nil && (resp == nil || !resp.IsError()) {
switch { switch {
case req.Operation == ReadOperation: case req.Operation == ReadOperation || req.Operation == HeaderOperation:
if resp == nil { if resp == nil {
return http.StatusNotFound, nil return http.StatusNotFound, nil
} }

View File

@ -42,6 +42,14 @@ func TestResponseUtil_RespondErrorCommon_basic(t *testing.T) {
respErr: nil, respErr: nil,
expectedStatus: 404, expectedStatus: 404,
}, },
{
title: "Header not found",
req: &Request{
Operation: HeaderOperation,
},
respErr: nil,
expectedStatus: 404,
},
{ {
title: "List with response and no keys", title: "List with response and no keys",
req: &Request{ req: &Request{