Add content type specification (#187)

This pr adds specifying the Content-Type header for requests with a body

Should be all requests but lmk if I missed any
This commit is contained in:
Flori 2023-08-18 11:59:14 +02:00 committed by GitHub
commit a9bbd51c2d
14 changed files with 36 additions and 10 deletions

View File

@ -22,7 +22,8 @@ impl Instance {
let chorus_request = ChorusRequest {
request: Client::new()
.post(endpoint_url)
.body(to_string(login_schema).unwrap()),
.body(to_string(login_schema).unwrap())
.header("Content-Type", "application/json"),
limit_type: LimitType::AuthLogin,
};
// We do not have a user yet, and the UserRateLimits will not be affected by a login

View File

@ -27,7 +27,8 @@ impl Instance {
let chorus_request = ChorusRequest {
request: Client::new()
.post(endpoint_url)
.body(to_string(register_schema).unwrap()),
.body(to_string(register_schema).unwrap())
.header("Content-Type", "application/json"),
limit_type: LimitType::AuthRegister,
};
// We do not have a user yet, and the UserRateLimits will not be affected by a login

View File

@ -75,6 +75,7 @@ impl Channel {
channel_id
))
.header("Authorization", user.token())
.header("Content-Type", "application/json")
.body(to_string(&modify_data).unwrap()),
limit_type: LimitType::Channel(channel_id),
};
@ -129,7 +130,8 @@ impl Channel {
self.id,
recipient_id
))
.header("Authorization", user.token());
.header("Authorization", user.token())
.header("Content-Type", "application/json");
if let Some(schema) = add_channel_recipient_schema {
request = request.body(to_string(&schema).unwrap());
}

View File

@ -27,7 +27,8 @@ impl Message {
request: Client::new()
.post(format!("{}/channels/{}/messages", url_api, channel_id))
.header("Authorization", user.token())
.body(to_string(&message).unwrap()),
.body(to_string(&message).unwrap())
.header("Content-Type", "application/json"),
limit_type: LimitType::Channel(channel_id),
};
chorus_request.deserialize_response::<Message>(user).await

View File

@ -43,6 +43,7 @@ impl types::Channel {
request: Client::new()
.put(url)
.header("Authorization", user.token())
.header("Content-Type", "application/json")
.body(body),
limit_type: LimitType::Channel(channel_id),
};

View File

@ -108,7 +108,10 @@ impl ReactionMeta {
emoji
);
let chorus_request = ChorusRequest {
request: Client::new().put(url).header("Authorization", user.token()),
request: Client::new()
.put(url)
.header("Authorization", user.token())
.header("Content-Type", "application/json"),
limit_type: LimitType::Channel(self.channel_id),
};
chorus_request.handle_request_as_result(user).await

View File

@ -24,6 +24,7 @@ impl Guild {
request: Client::new()
.post(url.clone())
.header("Authorization", user.token.clone())
.header("Content-Type", "application/json")
.body(to_string(&guild_create_schema).unwrap()),
limit_type: LimitType::Global,
};
@ -58,7 +59,8 @@ impl Guild {
let chorus_request = ChorusRequest {
request: Client::new()
.post(url.clone())
.header("Authorization", user.token.clone()),
.header("Authorization", user.token.clone())
.header("Content-Type", "application/json"),
limit_type: LimitType::Global,
};
chorus_request.handle_request_as_result(user).await
@ -157,6 +159,7 @@ impl Channel {
guild_id
))
.header("Authorization", user.token())
.header("Content-Type", "application/json")
.body(to_string(&schema).unwrap()),
limit_type: LimitType::Guild(guild_id),
};

View File

@ -53,7 +53,10 @@ impl types::GuildMember {
role_id
);
let chorus_request = ChorusRequest {
request: Client::new().put(url).header("Authorization", user.token()),
request: Client::new()
.put(url)
.header("Authorization", user.token())
.header("Content-Type", "application/json"),
limit_type: LimitType::Guild(guild_id),
};
chorus_request.handle_request_as_result(user).await

View File

@ -83,6 +83,7 @@ impl types::RoleObject {
request: Client::new()
.post(url)
.header("Authorization", user.token())
.header("Content-Type", "application/json")
.body(body),
limit_type: LimitType::Guild(guild_id),
};
@ -115,6 +116,7 @@ impl types::RoleObject {
request: Client::new()
.patch(url)
.header("Authorization", user.token())
.header("Content-Type", "application/json")
.body(body),
limit_type: LimitType::Guild(guild_id),
};
@ -150,6 +152,7 @@ impl types::RoleObject {
request: Client::new()
.patch(url)
.header("Authorization", user.token())
.header("Content-Type", "application/json")
.body(body),
limit_type: LimitType::Guild(guild_id),
};

View File

@ -31,6 +31,7 @@ impl UserMeta {
if session_id.is_some() {
request.request = request
.request
.header("Content-Type", "application/json")
.body(to_string(session_id.unwrap()).unwrap());
}
request.deserialize_response::<Invite>(self).await
@ -50,7 +51,8 @@ impl UserMeta {
self.belongs_to.borrow().urls.api
))
.body(to_string(&code).unwrap())
.header("Authorization", self.token()),
.header("Authorization", self.token())
.header("Content-Type", "application/json"),
limit_type: super::LimitType::Global,
}
.deserialize_response::<Invite>(self)
@ -77,6 +79,7 @@ impl UserMeta {
channel_id
))
.header("Authorization", self.token())
.header("Content-Type", "application/json")
.body(to_string(&create_channel_invite_schema).unwrap()),
limit_type: super::LimitType::Channel(channel_id),
}

View File

@ -26,6 +26,7 @@ impl UserMeta {
request: Client::new()
.post(url)
.header("Authorization", self.token())
.header("Content-Type", "application/json")
.body(to_string(&create_private_channel_schema).unwrap()),
limit_type: LimitType::Global,
}

View File

@ -23,6 +23,7 @@ impl UserMeta {
guild_id
))
.header("Authorization", self.token())
.header("Content-Type", "application/json")
.body(to_string(&lurking).unwrap()),
limit_type: crate::api::LimitType::Guild(*guild_id),
}

View File

@ -69,6 +69,7 @@ impl UserMeta {
request: Client::new()
.post(url)
.header("Authorization", self.token())
.header("Content-Type", "application/json")
.body(body),
limit_type: LimitType::Global,
};

View File

@ -50,7 +50,8 @@ impl UserMeta {
let request = Client::new()
.patch(format!("{}/users/@me", self.belongs_to.borrow().urls.api))
.body(to_string(&modify_schema).unwrap())
.header("Authorization", self.token());
.header("Authorization", self.token())
.header("Content-Type", "application/json");
let chorus_request = ChorusRequest {
request,
limit_type: LimitType::default(),
@ -68,7 +69,8 @@ impl UserMeta {
"{}/users/@me/delete",
self.belongs_to.borrow().urls.api
))
.header("Authorization", self.token());
.header("Authorization", self.token())
.header("Content-Type", "application/json");
let chorus_request = ChorusRequest {
request,
limit_type: LimitType::default(),