mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 16:57:22 +00:00
feat: rest header injection (#3122)
* feat: made some progress on a function which can be overridden to allow users to inject custom headers into a rest request * made the changes suggested in PR. Renamed inject headers to createBaseHeaders, which adds the user agent into the headers.
This commit is contained in:
@@ -98,10 +98,17 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
|
||||
|
||||
routes: createRoutes(),
|
||||
|
||||
createBaseHeaders() {
|
||||
return {
|
||||
'user-agent': `DiscordBot (https://github.com/discordeno/discordeno, v${version})`,
|
||||
}
|
||||
},
|
||||
|
||||
checkRateLimits(url, headers) {
|
||||
const authHeader = headers?.authorization ?? ''
|
||||
|
||||
const ratelimited = rest.rateLimitedPaths.get(`${authHeader}${url}`)
|
||||
|
||||
const global = rest.rateLimitedPaths.get('global')
|
||||
const now = Date.now()
|
||||
|
||||
@@ -161,9 +168,7 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
|
||||
},
|
||||
|
||||
createRequestBody(method, options) {
|
||||
const headers: Record<string, string> = {
|
||||
'user-agent': `DiscordBot (https://github.com/discordeno/discordeno, v${version})`,
|
||||
}
|
||||
const headers = this.createBaseHeaders()
|
||||
|
||||
if (options?.unauthorized !== true) headers.authorization = `Bot ${rest.token}`
|
||||
|
||||
|
||||
@@ -176,6 +176,8 @@ export interface RestManager {
|
||||
invalidBucket: InvalidRequestBucket
|
||||
/** The routes that are available for this manager. */
|
||||
routes: RestRoutes
|
||||
/** Allows the user to inject custom headers that will be sent with every request. */
|
||||
createBaseHeaders: () => Record<string, string>
|
||||
/** Whether or not the rest manager should keep objects in raw snake case from discord. */
|
||||
preferSnakeCase: (enabled: boolean) => RestManager
|
||||
/** Check the rate limits for a url or a bucket. */
|
||||
|
||||
Reference in New Issue
Block a user