mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-10 19:52:53 +00:00
fix: failing native http requests with body
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {Requestor} from '@openid/appauth';
|
||||
import {Http, HttpHeaders, HttpResponse} from '@capacitor-community/http';
|
||||
import {CapacitorHttp, HttpHeaders, HttpResponse} from '@capacitor/core';
|
||||
import {XhrSettings} from 'ionic-appauth/lib/cordova';
|
||||
|
||||
// REQUIRES CAPACITOR PLUGIN
|
||||
@@ -25,28 +25,46 @@ export class CapacitorRequestor extends Requestor {
|
||||
}
|
||||
|
||||
private async get<T>(url: string, headers: HttpHeaders) {
|
||||
return Http.get({url, headers}).then(
|
||||
return CapacitorHttp.get({url, headers}).then(
|
||||
(response: HttpResponse) => response.data as T,
|
||||
);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
private async post<T>(url: string, data: any, headers: HttpHeaders) {
|
||||
return Http.post({url, data: data, headers}).then(
|
||||
(response: HttpResponse) => response.data as T,
|
||||
);
|
||||
return CapacitorHttp.post({
|
||||
url,
|
||||
data: this.decodeURLSearchParams(data),
|
||||
headers,
|
||||
}).then((response: HttpResponse) => {
|
||||
return response.data as T;
|
||||
});
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
private async put<T>(url: string, data: any, headers: HttpHeaders) {
|
||||
return Http.put({url, data, headers}).then(
|
||||
return CapacitorHttp.put({
|
||||
url,
|
||||
data: this.decodeURLSearchParams(data),
|
||||
headers,
|
||||
}).then((response: HttpResponse) => response.data as T);
|
||||
}
|
||||
|
||||
private async delete<T>(url: string, headers: HttpHeaders) {
|
||||
return CapacitorHttp.delete({url, headers}).then(
|
||||
(response: HttpResponse) => response.data as T,
|
||||
);
|
||||
}
|
||||
|
||||
private async delete<T>(url: string, headers: HttpHeaders) {
|
||||
return Http.del({url, headers}).then(
|
||||
(response: HttpResponse) => response.data as T,
|
||||
private decodeURLSearchParams(parameters: string): Record<string, unknown> {
|
||||
const searchParameters = new URLSearchParams(parameters);
|
||||
return Object.fromEntries(
|
||||
[...searchParameters.keys()].map(k => [
|
||||
k,
|
||||
searchParameters.getAll(k).length === 1
|
||||
? searchParameters.get(k)
|
||||
: searchParameters.getAll(k),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user