hashicorp / hashicorp/vault-client-dotnet

PATCH request overrides content type causing errors

Open
#203 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
48
Forks
6
PR merge metrics
No merged PRs in 30d

Description

# Expected Behavior

Vault API Patch endpoint requires 'Content-Type: application/merge-patch+json' header, otherwise it fails with an error.
HashiCorp.Vault client has AsynchronousClient.PatchAsync method, which should run successfully, if HeaderParameters include Content-Type set to application/merge-patch+json.

# Current Behavior

Currently ApiClient will overwrite content-type during patch call here:
https://github.com/hashicorp/vault-client-dotnet/blob/main/src/Vault/Client/ApiClient.cs#L466

Content-Type is initially loaded from HeaderParameters here: https://github.com/hashicorp/vault-client-dotnet/blob/main/src/Vault/Client/ApiClient.cs#L440 however its not really used in the case where PatchAsync method is called.

# Failure Information

HashiCorp.Vault 0.3.0
net8.0

## Steps to Reproduce

Following code will fail with the incorrect content type error, because the content type added through HeaderParameters is not used:

```
var data = "{ \"data\": { \"test\": \asdasdasd\" } }";
var requestOptions = new RequestOptions { Data = data };
requestOptions.HeaderParameters.Add("Content-Type", "application/merge-patch+json");
await vaultClient.Secrets.AsynchronousClient.PatchAsync(path, options);
```

# Additional Information

It's quite visible from the NewRequest method where things go wrong. Its also visible in the documentation https://developer.hashicorp.com/vault/docs/commands/patch that specific content type is required for the method to succeed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.