From 19d0cf20037c631408505ce56ab7373930aaf900 Mon Sep 17 00:00:00 2001 From: "Jingwei.Zhang" Date: Wed, 21 Sep 2022 16:32:47 +0800 Subject: [PATCH] fix: fix octavia request headers Add accept:application/json to all the octavia requests, to get the return data in json format, otherwise it may get the return data in xml format Closes-Bug: #1990250 Change-Id: Ibb3c2540225631ba9d3c972d5ac123d8b007d4e8 --- src/client/octavia/index.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/client/octavia/index.js b/src/client/octavia/index.js index d109c042..68b6d904 100644 --- a/src/client/octavia/index.js +++ b/src/client/octavia/index.js @@ -20,6 +20,40 @@ export class OctaviaClient extends Base { return octaviaBase(); } + get request() { + const request = this.originRequest; + if (!this.enable) { + return super.request; + } + const updateConfig = (conf) => { + const { headers = {}, ...rest } = conf || {}; + const newConf = { + headers: { + accept: 'application/json', + ...headers, + }, + ...rest, + }; + return newConf; + }; + return { + get: (url, params, conf) => + request.get(this.getUrl(url), params, updateConfig(conf)), + post: (url, data, params, conf) => + request.post(this.getUrl(url), data, params, updateConfig(conf)), + put: (url, data, params, conf) => + request.put(this.getUrl(url), data, params, updateConfig(conf)), + delete: (url, data, params, conf) => + request.delete(this.getUrl(url), data, params, updateConfig(conf)), + patch: (url, data, params, conf) => + request.patch(this.getUrl(url), data, params, updateConfig(conf)), + head: (url, params, conf) => + request.head(this.getUrl(url), params, updateConfig(conf)), + copy: (url, params, conf) => + request.copy(this.getUrl(url), params, updateConfig(conf)), + }; + } + get resources() { return [ {