-
Notifications
You must be signed in to change notification settings - Fork 290
Add Content-Type to finalize request in KV client #1147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Content-Type to finalize request in KV client #1147
Conversation
@@ -21,7 +21,8 @@ impl SetSecretBuilder { | |||
|
|||
let body = Some(Value::Object(request_body).to_string().into()); | |||
|
|||
let headers = Headers::new(); | |||
let mut headers = Headers::new(); | |||
headers.insert(CONTENT_TYPE, "application/json"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be a larger problem than just SetSecretBuilder. Setting the content type was mistakenly dropped in #962.
Instead of updating just SetSecretBuilder, can you instead update finalize_request
?
Perhaps something like this:
--- a/sdk/security_keyvault/src/clients/keyvault_client.rs
+++ b/sdk/security_keyvault/src/clients/keyvault_client.rs
@@ -4,7 +4,8 @@ use azure_core::{
date,
error::{Error, ErrorKind},
headers::*,
- Body, Context, Method, Pipeline, Request, Response,
+ prelude::*,
+ Body, Method, Pipeline, Request, Response,
};
use const_format::formatcp;
use std::sync::Arc;
@@ -84,6 +85,9 @@ impl KeyvaultClient {
request.insert_header(MS_DATE, time);
if let Some(request_body) = request_body {
+ if request.headers().get_optional_str(&CONTENT_TYPE).is_none() {
+ request.insert_headers(&ContentType::APPLICATION_JSON);
+ }
request.insert_header(CONTENT_LENGTH, request_body.len().to_string());
request.set_body(request_body);
} else {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, if you'd prefer, let me know and I can make the broader change.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do it, I was just thinking that the other operations (get, delete, get_versions) are working without the Content-Type
header, hence putting it into the common finalize_request
method seemed incorrect to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but your suggestion make sense that for request with body it should be added, in case in the future there are other operation which need to set the header. I will change it according to your suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get & delete do not set request bodies, which makes this less of an issue.
14ce7e2
to
aa3868d
Compare
Thanks for the PR! |
No problem |
Fixes #1146