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:
parent
89fa73c9f7
commit
2fcaec4b21
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:improvement
|
||||||
|
http: Support responding to HEAD operation from plugins
|
||||||
|
```
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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{
|
||||||
|
|
Loading…
Reference in New Issue