1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

Fixed networking

This commit is contained in:
Laurent Cozic 2020-10-14 16:54:42 +01:00
parent 6ff45ce485
commit 0c0d228815
4 changed files with 27 additions and 3 deletions

View File

@ -17,6 +17,7 @@
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/AppTheme">
<!-- RN-NOTIFICATION -->

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
<certificates src="user"/>
</trust-anchors>
</base-config>
</network-security-config>

View File

@ -335,14 +335,22 @@ class WebDavApi {
// </d:propfind>'
async exec(method, path = '', body = null, headers = null, options = null) {
if (headers === null) headers = {};
if (options === null) options = {};
headers = Object.assign({}, headers);
options = Object.assign({}, options);
if (!options.responseFormat) options.responseFormat = 'json';
if (!options.target) options.target = 'string';
const authToken = this.authToken();
if (authToken) headers['Authorization'] = `Basic ${authToken}`;
// That should not be needed, but it is required for React Native 0.63+
// https://github.com/facebook/react-native/issues/30176
if (!headers['Content-Type']) {
if (method === 'PROPFIND') headers['Content-Type'] = 'text/xml';
if (method === 'PUT') headers['Content-Type'] = 'text/plain';
}
// On iOS, the network lib appends a If-None-Match header to PROPFIND calls, which is kind of correct because
// the call is idempotent and thus could be cached. According to RFC-7232 though only GET and HEAD should have
@ -365,7 +373,6 @@ class WebDavApi {
if (shim.httpAgent(url)) fetchOptions.agent = shim.httpAgent(url);
let response = null;
// console.info('WebDAV Call', `${method} ${url}`, headers, options);

View File

@ -44,6 +44,13 @@ function shimInit() {
if (!validatedUrl) throw new Error(`Not a valid URL: ${url}`);
return shim.fetchWithRetry(() => {
// If the request has a body and it's not a GET call, and it doesn't have a Content-Type header
// we display a warning, because it could trigger a "Network request failed" error.
// https://github.com/facebook/react-native/issues/30176
if (options?.body && options?.method && options.method !== 'GET' && !options?.headers?.['Content-Type']) {
console.warn('Done a non-GET fetch call without a Content-Type header. It may make the request fail.', url, options);
}
return fetch(validatedUrl, options);
}, options);
};