Skip to content

Commit

Permalink
refs #1515 Add encoding header to avoid the axios issue
Browse files Browse the repository at this point in the history
  • Loading branch information
h3poteto committed Dec 29, 2022
1 parent 3782a42 commit 2e2d2df
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 20 deletions.
72 changes: 64 additions & 8 deletions megalodon/src/mastodon/api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ namespace MastodonAPI {
): Promise<Response<T>> {
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
}
Expand Down Expand Up @@ -123,7 +130,14 @@ namespace MastodonAPI {
*/
public async put<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
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
}
Expand Down Expand Up @@ -168,7 +182,14 @@ namespace MastodonAPI {
*/
public async putForm<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
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
}
Expand Down Expand Up @@ -213,7 +234,14 @@ namespace MastodonAPI {
*/
public async patch<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
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
}
Expand Down Expand Up @@ -258,7 +286,14 @@ namespace MastodonAPI {
*/
public async patchForm<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
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
}
Expand Down Expand Up @@ -303,7 +338,14 @@ namespace MastodonAPI {
*/
public async post<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
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
}
Expand Down Expand Up @@ -339,7 +381,14 @@ namespace MastodonAPI {
*/
public async postForm<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
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
}
Expand Down Expand Up @@ -376,7 +425,14 @@ namespace MastodonAPI {
public async del<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
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
}
Expand Down
4 changes: 3 additions & 1 deletion megalodon/src/mastodon/web_socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion megalodon/src/misskey/api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,14 @@ namespace MisskeyAPI {
*/
public async post<T>(path: string, params: any = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
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
}
Expand Down
4 changes: 3 additions & 1 deletion megalodon/src/misskey/web_socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 64 additions & 8 deletions megalodon/src/pleroma/api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,14 @@ namespace PleromaAPI {
public async get<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
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, {
Expand Down Expand Up @@ -346,7 +353,14 @@ namespace PleromaAPI {
*/
public async put<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
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
}
Expand Down Expand Up @@ -391,7 +405,14 @@ namespace PleromaAPI {
*/
public async putForm<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
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
}
Expand Down Expand Up @@ -436,7 +457,14 @@ namespace PleromaAPI {
*/
public async patch<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
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
}
Expand Down Expand Up @@ -481,7 +509,14 @@ namespace PleromaAPI {
*/
public async patchForm<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
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
}
Expand Down Expand Up @@ -526,7 +561,14 @@ namespace PleromaAPI {
*/
public async post<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
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
}
Expand Down Expand Up @@ -562,7 +604,14 @@ namespace PleromaAPI {
*/
public async postForm<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
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
}
Expand Down Expand Up @@ -599,7 +648,14 @@ namespace PleromaAPI {
public async del<T>(path: string, params = {}, headers: { [key: string]: string } = {}): Promise<Response<T>> {
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
}
Expand Down
4 changes: 3 additions & 1 deletion megalodon/src/pleroma/web_socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2e2d2df

Please sign in to comment.