From 2e2d2dff5188fc85c4bc40fa9d9e377819d40e23 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Thu, 29 Dec 2022 11:34:45 +0900
Subject: [PATCH] refs #1515 Add encoding header to avoid the axios issue
https://github.com/axios/axios/issues/5346
---
megalodon/src/mastodon/api_client.ts | 72 ++++++++++++++++++++++++----
megalodon/src/mastodon/web_socket.ts | 4 +-
megalodon/src/misskey/api_client.ts | 9 +++-
megalodon/src/misskey/web_socket.ts | 4 +-
megalodon/src/pleroma/api_client.ts | 72 ++++++++++++++++++++++++----
megalodon/src/pleroma/web_socket.ts | 4 +-
6 files changed, 145 insertions(+), 20 deletions(-)
diff --git a/megalodon/src/mastodon/api_client.ts b/megalodon/src/mastodon/api_client.ts
index 3ee7299b4..e6b6dbc14 100644
--- a/megalodon/src/mastodon/api_client.ts
+++ b/megalodon/src/mastodon/api_client.ts
@@ -78,7 +78,14 @@ namespace MastodonAPI {
): Promise> {
let options: AxiosRequestConfig = {
params: params,
- headers: headers,
+ headers: Object.assign(
+ {
+ 'User-Agent': this.userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
+ },
+ headers
+ ),
maxContentLength: Infinity,
maxBodyLength: Infinity
}
@@ -123,7 +130,14 @@ namespace MastodonAPI {
*/
public async put(path: string, params = {}, headers: { [key: string]: string } = {}): Promise> {
let options: AxiosRequestConfig = {
- headers: headers,
+ headers: Object.assign(
+ {
+ 'User-Agent': this.userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
+ },
+ headers
+ ),
maxContentLength: Infinity,
maxBodyLength: Infinity
}
@@ -168,7 +182,14 @@ namespace MastodonAPI {
*/
public async putForm(path: string, params = {}, headers: { [key: string]: string } = {}): Promise> {
let options: AxiosRequestConfig = {
- headers: headers,
+ headers: Object.assign(
+ {
+ 'User-Agent': this.userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
+ },
+ headers
+ ),
maxContentLength: Infinity,
maxBodyLength: Infinity
}
@@ -213,7 +234,14 @@ namespace MastodonAPI {
*/
public async patch(path: string, params = {}, headers: { [key: string]: string } = {}): Promise> {
let options: AxiosRequestConfig = {
- headers: headers,
+ headers: Object.assign(
+ {
+ 'User-Agent': this.userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
+ },
+ headers
+ ),
maxContentLength: Infinity,
maxBodyLength: Infinity
}
@@ -258,7 +286,14 @@ namespace MastodonAPI {
*/
public async patchForm(path: string, params = {}, headers: { [key: string]: string } = {}): Promise> {
let options: AxiosRequestConfig = {
- headers: headers,
+ headers: Object.assign(
+ {
+ 'User-Agent': this.userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
+ },
+ headers
+ ),
maxContentLength: Infinity,
maxBodyLength: Infinity
}
@@ -303,7 +338,14 @@ namespace MastodonAPI {
*/
public async post(path: string, params = {}, headers: { [key: string]: string } = {}): Promise> {
let options: AxiosRequestConfig = {
- headers: headers,
+ headers: Object.assign(
+ {
+ 'User-Agent': this.userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
+ },
+ headers
+ ),
maxContentLength: Infinity,
maxBodyLength: Infinity
}
@@ -339,7 +381,14 @@ namespace MastodonAPI {
*/
public async postForm(path: string, params = {}, headers: { [key: string]: string } = {}): Promise> {
let options: AxiosRequestConfig = {
- headers: headers,
+ headers: Object.assign(
+ {
+ 'User-Agent': this.userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
+ },
+ headers
+ ),
maxContentLength: Infinity,
maxBodyLength: Infinity
}
@@ -376,7 +425,14 @@ namespace MastodonAPI {
public async del(path: string, params = {}, headers: { [key: string]: string } = {}): Promise> {
let options: AxiosRequestConfig = {
data: params,
- headers: headers,
+ headers: Object.assign(
+ {
+ 'User-Agent': this.userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
+ },
+ headers
+ ),
maxContentLength: Infinity,
maxBodyLength: Infinity
}
diff --git a/megalodon/src/mastodon/web_socket.ts b/megalodon/src/mastodon/web_socket.ts
index 2d4b0d087..ce4a89535 100644
--- a/megalodon/src/mastodon/web_socket.ts
+++ b/megalodon/src/mastodon/web_socket.ts
@@ -52,7 +52,9 @@ export default class WebSocket extends EventEmitter implements WebSocketInterfac
}
this.parser = new Parser()
this.headers = {
- 'User-Agent': userAgent
+ 'User-Agent': userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
}
this.proxyConfig = proxyConfig
this._accessToken = accessToken
diff --git a/megalodon/src/misskey/api_client.ts b/megalodon/src/misskey/api_client.ts
index a9f0cfd03..edec74a10 100644
--- a/megalodon/src/misskey/api_client.ts
+++ b/megalodon/src/misskey/api_client.ts
@@ -470,7 +470,14 @@ namespace MisskeyAPI {
*/
public async post(path: string, params: any = {}, headers: { [key: string]: string } = {}): Promise> {
let options: AxiosRequestConfig = {
- headers: headers,
+ headers: Object.assign(
+ {
+ 'User-Agent': this.userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
+ },
+ headers
+ ),
maxContentLength: Infinity,
maxBodyLength: Infinity
}
diff --git a/megalodon/src/misskey/web_socket.ts b/megalodon/src/misskey/web_socket.ts
index b0f092c6e..9f16f3e17 100644
--- a/megalodon/src/misskey/web_socket.ts
+++ b/megalodon/src/misskey/web_socket.ts
@@ -48,7 +48,9 @@ export default class WebSocket extends EventEmitter implements WebSocketInterfac
this.parser = new Parser()
this.channel = channel
this.headers = {
- 'User-Agent': userAgent
+ 'User-Agent': userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
}
if (listId === undefined) {
this.listId = null
diff --git a/megalodon/src/pleroma/api_client.ts b/megalodon/src/pleroma/api_client.ts
index d45bc861b..ee331bd12 100644
--- a/megalodon/src/pleroma/api_client.ts
+++ b/megalodon/src/pleroma/api_client.ts
@@ -303,7 +303,14 @@ namespace PleromaAPI {
public async get(path: string, params = {}, headers: { [key: string]: string } = {}): Promise> {
let options: AxiosRequestConfig = {
params: params,
- headers: headers
+ headers: Object.assign(
+ {
+ 'User-Agent': this.userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
+ },
+ headers
+ )
}
if (this.accessToken) {
options = objectAssignDeep({}, options, {
@@ -346,7 +353,14 @@ namespace PleromaAPI {
*/
public async put(path: string, params = {}, headers: { [key: string]: string } = {}): Promise> {
let options: AxiosRequestConfig = {
- headers: headers,
+ headers: Object.assign(
+ {
+ 'User-Agent': this.userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
+ },
+ headers
+ ),
maxContentLength: Infinity,
maxBodyLength: Infinity
}
@@ -391,7 +405,14 @@ namespace PleromaAPI {
*/
public async putForm(path: string, params = {}, headers: { [key: string]: string } = {}): Promise> {
let options: AxiosRequestConfig = {
- headers: headers,
+ headers: Object.assign(
+ {
+ 'User-Agent': this.userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
+ },
+ headers
+ ),
maxContentLength: Infinity,
maxBodyLength: Infinity
}
@@ -436,7 +457,14 @@ namespace PleromaAPI {
*/
public async patch(path: string, params = {}, headers: { [key: string]: string } = {}): Promise> {
let options: AxiosRequestConfig = {
- headers: headers,
+ headers: Object.assign(
+ {
+ 'User-Agent': this.userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
+ },
+ headers
+ ),
maxContentLength: Infinity,
maxBodyLength: Infinity
}
@@ -481,7 +509,14 @@ namespace PleromaAPI {
*/
public async patchForm(path: string, params = {}, headers: { [key: string]: string } = {}): Promise> {
let options: AxiosRequestConfig = {
- headers: headers,
+ headers: Object.assign(
+ {
+ 'User-Agent': this.userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
+ },
+ headers
+ ),
maxContentLength: Infinity,
maxBodyLength: Infinity
}
@@ -526,7 +561,14 @@ namespace PleromaAPI {
*/
public async post(path: string, params = {}, headers: { [key: string]: string } = {}): Promise> {
let options: AxiosRequestConfig = {
- headers: headers,
+ headers: Object.assign(
+ {
+ 'User-Agent': this.userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
+ },
+ headers
+ ),
maxContentLength: Infinity,
maxBodyLength: Infinity
}
@@ -562,7 +604,14 @@ namespace PleromaAPI {
*/
public async postForm(path: string, params = {}, headers: { [key: string]: string } = {}): Promise> {
let options: AxiosRequestConfig = {
- headers: headers,
+ headers: Object.assign(
+ {
+ 'User-Agent': this.userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
+ },
+ headers
+ ),
maxContentLength: Infinity,
maxBodyLength: Infinity
}
@@ -599,7 +648,14 @@ namespace PleromaAPI {
public async del(path: string, params = {}, headers: { [key: string]: string } = {}): Promise> {
let options: AxiosRequestConfig = {
data: params,
- headers: headers,
+ headers: Object.assign(
+ {
+ 'User-Agent': this.userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
+ },
+ headers
+ ),
maxContentLength: Infinity,
maxBodyLength: Infinity
}
diff --git a/megalodon/src/pleroma/web_socket.ts b/megalodon/src/pleroma/web_socket.ts
index e2aa29990..842d25581 100644
--- a/megalodon/src/pleroma/web_socket.ts
+++ b/megalodon/src/pleroma/web_socket.ts
@@ -53,7 +53,9 @@ export default class WebSocket extends EventEmitter implements WebSocketInterfac
}
this.parser = new Parser()
this.headers = {
- 'User-Agent': userAgent
+ 'User-Agent': userAgent,
+ // To avoid: https://github.com/axios/axios/issues/5346
+ 'Accept-Encoding': 'gzip,deflate,compress'
}
this.proxyConfig = proxyConfig
this._accessToken = accessToken