agent/caching: proxy redirect and non-json responses; update tests (#6353)

* agent/caching: proxy redirect and non-json responses; update tests

* agent/caching: do not wrap error responses as internal errors, simply proxy them back as-is

* minor refactoring of APIProxy.Send logic

* add test case to ensure error response is not wrapped
This commit is contained in:
Calvin Leung Huang
2019-03-06 17:23:20 -08:00
committed by GitHub
parent 07b18eef6b
commit ba86e6bbd5
6 changed files with 133 additions and 96 deletions

View File

@@ -45,13 +45,15 @@ func (ap *APIProxy) Send(ctx context.Context, req *SendRequest) (*SendResponse,
// Make the request to Vault and get the response
ap.logger.Info("forwarding request", "path", req.Request.URL.Path, "method", req.Request.Method)
resp, err := client.RawRequestWithContext(ctx, fwReq)
if err != nil {
return nil, err
}
sendResponse := &SendResponse{
Response: resp,
var sendResponse *SendResponse
resp, err := client.RawRequestWithContext(ctx, fwReq)
if resp != nil {
sendResponse = &SendResponse{Response: resp}
}
if err != nil {
// Bubble back the api.Response as well for error checking/handling at the handler layer.
return sendResponse, err
}
// Set SendResponse.ResponseBody if the response body is non-nil