mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 18:48:08 +00:00 
			
		
		
		
	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:
		
							
								
								
									
										3
									
								
								changelog/19520.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								changelog/19520.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -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{ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Alexander Scheel
					Alexander Scheel