Skip to content

PATCH request overrides content type causing errors #203

Description

@skatanski

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<T>(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions