From 986413d4334607813976b92f21dd2f7b77da0df6 Mon Sep 17 00:00:00 2001 From: Bing Sun Date: Wed, 13 May 2020 11:31:33 +0800 Subject: [PATCH] postgest: apply xhr config before additional xhr hook --- src/postgrest.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/postgrest.js b/src/postgrest.js index 897178e..f06eb93 100644 --- a/src/postgrest.js +++ b/src/postgrest.js @@ -110,11 +110,20 @@ export default (api_root, auth={}) => { // 2. return values on Prefer // if (['POST', 'PATCH'].includes(options.method) && options.headers && !options.headers.Prefer) - if (['POST', 'PATCH'].includes(options.method)) + if (['POST', 'PATCH'].includes(options.method)) { + // if the config is already set + let _old_config = options.config + options.config = xhr => { + // apply the provided xhr config + let _old_config_xhr = _old_config(xhr) + if (_old_config_xhr) + xhr = _old_config_xhr + xhr.setRequestHeader('Prefer', 'return=representation') return xhr } + } // normalize params: since options.params is an object, it cannot support // duplicated query keys, while postgrest supports that.