javascript: Missing Content-Type header on patch operation
Hi,
Everytime I try to patch a node, I hit a HTTP 415
the server responded with the status code 415 but did not return more information.
After some researches, I found that the API wait for Content-Type: application/strategic-merge-patch+json header for PATCH operations.
But this header is not set.
Is there any way I can override headers before sending the request ?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 22 (13 by maintainers)
Commits related to this issue
- Add merge header to patch methods The @kubernetes/client-node does not send the proper Content-Type header when hitting the patch API endpoints, see https://github.com/kubernetes-client/javascript/is... — committed to atomist/sdm-pack-k8s by deleted user 5 years ago
- Change update call. See: https://github.com/kubernetes-client/javascript/issues/19#issuecomment-582886605 — committed to juice-shop/multi-juicer by J12934 4 years ago
- Specify swagger-codegen version to pull in optional header override v2.4.2 includes the change to (optionally) override/set headers on every call. See https://github.com/kubernetes-client/javascript/... — committed to johnfrench3/Awesome-javascript-Project-build by deleted user 5 years ago
- Change update call. See: https://github.com/kubernetes-client/javascript/issues/19#issuecomment-582886605 — committed to goldenlight123/multi-juicer by goldenlight123 4 years ago
- Specify swagger-codegen version to pull in optional header override v2.4.2 includes the change to (optionally) override/set headers on every call. See https://github.com/kubernetes-client/javascript/... — committed to mattstern31/javascript by mattstern31 5 years ago
For anyone still running into this, the solution suggested doesn’t work as described anymore as the function signature has changed slightly.
The function now has more args which need to come before the options array, also passing
nullmakes the api client pass empty values for dryRun and co. instead of skipping it. Passingundefinedinstead ofnullworks for me.What works for me (
@kubernetes/client-node@0.11.1) is:Ok, we have the workaround nowadays to specify custom http headers with request , as described in https://github.com/kubernetes-client/javascript/issues/19#issuecomment-497534040. But this still is not the real solution to PATCH calls.
Why is “Content-Type”: “application/merge-patch+json” simply not the default for patch operations? 😦
I can take a pass at trying to change swagger-codegen.
I created an issue on swagger-codegen https://github.com/swagger-api/swagger-codegen/issues/9035 and created a strawperson proposal for a solution https://github.com/swagger-api/swagger-codegen/pull/9036.
Shouldn’t
PATCHoperations have theContent-Typeheader set toapplication/strategic-merge-patch+jsonby default. It is kind of annoying to use this client if you have to mutate the client object before every patch operation.I.e. it would greatly improve the usability of this client if the patch operations in
api.tswith:@runarberg I agree this is what’s missing. The swagger spec clearly states that this endpoint “consumes”:
["application/json-patch+json", "application/merge-patch+json", "application/strategic-merge-patch+json"].And since this file is generated from the swagger spec I’m guessing something have to be done over at swagger-codegen or at the gen part of this project. @brendanburns could you help out to answer this? I started looking at a permanent solution but it was a lot to go through.
For anyone who’s stumbling across this issue and needs a workaround similar to the one of @msonnabaum but a bit more generic:
Right, that makes sense.
This seemed to work to solve my immediate problem:
I appreciate you reopening the issue though so we can get a client-side fix in.